У меня есть веб-сервис на C #
и программа, которая отправляет данные в Java
вот часть веб-сервиса:
[WebMethod]
public string Client(string request) {
return "Hello" + request;
}
А это часть Java:
public void send (String url)
{
пытаться
{
URL obj = новый URL (URL);
HttpURLConnection con = (HttpURLConnection) obj.openConnection ();
//add reuqest header
con.setRequestMethod("POST");
con.setRequestProperty("User-Agent", "Mozilla/5.0");
con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
con.setRequestProperty("Content-Type", "application/json; charset=utf-8");
String urlParameters = "request="+this.toJson();
// Send post request
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
int responseCode = con.getResponseCode();
System.out.println("\nSending 'POST' request to URL : " + url);
System.out.println("Post parameters : " + urlParameters);
System.out.println("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
//print result
System.out.println(response.toString());
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
}
}
Я всегда приведу код 500
Если я использую не веб-сервис, просто простой asp.net mvc
связь работает
что мне нужно изменить / проверить в WebService для установления соединения?
* +1016 * UPDATE:
Я прилагаю wsdl:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<wsdl:definitions xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://tempuri.org/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://tempuri.org/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<s:element name="Client">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="request" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="ClientResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="ClientResult" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="string" nillable="true" type="s:string"/>
</s:schema>
</wsdl:types>
<wsdl:message name="ClientSoapIn">
<wsdl:part name="parameters" element="tns:Client"/>
</wsdl:message>
<wsdl:message name="ClientSoapOut">
<wsdl:part name="parameters" element="tns:ClientResponse"/>
</wsdl:message>
<wsdl:message name="ClientHttpGetIn">
<wsdl:part name="request" type="s:string"/>
</wsdl:message>
<wsdl:message name="ClientHttpGetOut">
<wsdl:part name="Body" element="tns:string"/>
</wsdl:message>
<wsdl:message name="ClientHttpPostIn">
<wsdl:part name="request" type="s:string"/>
</wsdl:message>
<wsdl:message name="ClientHttpPostOut">
<wsdl:part name="Body" element="tns:string"/>
</wsdl:message>
<wsdl:portType name="WeightServerSoap">
<wsdl:operation name="Client">
<wsdl:input message="tns:ClientSoapIn"/>
<wsdl:output message="tns:ClientSoapOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:portType name="WeightServerHttpGet">
<wsdl:operation name="Client">
<wsdl:input message="tns:ClientHttpGetIn"/>
<wsdl:output message="tns:ClientHttpGetOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:portType name="WeightServerHttpPost">
<wsdl:operation name="Client">
<wsdl:input message="tns:ClientHttpPostIn"/>
<wsdl:output message="tns:ClientHttpPostOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="WeightServerSoap" type="tns:WeightServerSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="Client">
<soap:operation soapAction="http://tempuri.org/Client" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="WeightServerSoap12" type="tns:WeightServerSoap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="Client">
<soap12:operation soapAction="http://tempuri.org/Client" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="WeightServerHttpGet" type="tns:WeightServerHttpGet">
<http:binding verb="GET"/>
<wsdl:operation name="Client">
<http:operation location="/Client"/>
<wsdl:input>
<http:urlEncoded/>
</wsdl:input>
<wsdl:output>
<mime:mimeXml part="Body"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="WeightServerHttpPost" type="tns:WeightServerHttpPost">
<http:binding verb="POST"/>
<wsdl:operation name="Client">
<http:operation location="/Client"/>
<wsdl:input>
<mime:content type="application/x-www-form-urlencoded"/>
</wsdl:input>
<wsdl:output>
<mime:mimeXml part="Body"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="WeightServer">
<wsdl:port name="WeightServerSoap" binding="tns:WeightServerSoap">
<soap:address location="http://localhost:55971/WeightServer.asmx"/>
</wsdl:port>
<wsdl:port name="WeightServerSoap12" binding="tns:WeightServerSoap12">
<soap12:address location="http://localhost:55971/WeightServer.asmx"/>
</wsdl:port>
<wsdl:port name="WeightServerHttpGet" binding="tns:WeightServerHttpGet">
<http:address location="http://localhost:55971/WeightServer.asmx"/>
</wsdl:port>
<wsdl:port name="WeightServerHttpPost" binding="tns:WeightServerHttpPost">
<http:address location="http://localhost:55971/WeightServer.asmx"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>