Hallo Zusammen
Ich habe Probleme den SOAP-Header für ein Web-Service zu setzen.
Ich habe zwei Clients, ein C# und ein Java Client, die auf den selben Service zugreifen.
Mit dem C# Client funktioniert alles einwandfrei, doch mit dem Java Client funktioniert es nicht.
Mit dem C# Client schicke ich folgenden Header:
Mit dem Java Client diesen:
Mit dem Java Client, hat bei meinem Service die UserId den Wert null und die RegGuid 00000000-0000-0000-0000-000000000000.
Mein Java Code
Das wsdl von meinem Service
Was mach ich falsch? Kann mir jemand weiterhelfen?
Besten Dank im Voraus!
Ich habe Probleme den SOAP-Header für ein Web-Service zu setzen.
Ich habe zwei Clients, ein C# und ein Java Client, die auf den selben Service zugreifen.
Mit dem C# Client funktioniert alles einwandfrei, doch mit dem Java Client funktioniert es nicht.
Mit dem C# Client schicke ich folgenden Header:
XML:
?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<AuthHeader xmlns="http://tempuri.org/">
<UserId>userid</UserId>
<RegGuid>87f64f72-97aa-4d61-9bac-db0acfdec997</RegGuid>
</AuthHeader>
</soap:Header>
<soap:Body>
<HelloWorld xmlns="http://tempuri.org/"/>
</soap:Body>
</soap:Envelope>
Mit dem Java Client diesen:
XML:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Header>
<AuthHeader soapenv:mustUnderstand="0" xmlns="http://tempuri.org/">
<UserId>userid</UserId>
<RegGuid>87f64f72-97aa-4d61-9bac-db0acfdec997</RegGuid>
</AuthHeader>
</soap:Header>
<soap:Body>
<HelloWorld xmlns="http://tempuri.org/"/>
</soap:Body>
</soap:Envelope>
Mit dem Java Client, hat bei meinem Service die UserId den Wert null und die RegGuid 00000000-0000-0000-0000-000000000000.
Mein Java Code
Code:
WebService1SoapProxy service = new WebService1SoapProxy();
WebService1SoapStub ws = new WebService1SoapStub();
ws = (WebService1SoapStub)service.getWebService1Soap();
SOAPHeaderElement header = new SOAPHeaderElement("http://tempuri.org/", "AuthHeader");
header.setMustUnderstand(false);
header.setNamespaceURI("http://tempuri.org/");
SOAPElement soapElement = header.addChildElement("UserId", "Credentials");
soapElement.addTextNode("userid");
soapElement = header.addChildElement("RegGuid", "Credentials");
soapElement.addTextNode("87f64f72-97aa-4d61-9bac-db0acfdec997");
SOAPFactory soapFactory = SOAPFactory.newInstance();
ws.setHeader(header);
System.out.println(ws.helloWorld());
Das wsdl von meinem Service
XML:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 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:s1="http://microsoft.com/wsdl/types/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://tempuri.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
<s:import namespace="http://microsoft.com/wsdl/types/"/>
<s:element name="HelloWorld">
<s:complexType/>
</s:element>
<s:element name="HelloWorldResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="HelloWorldResult" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="AuthHeader" type="tns:AuthHeader"/>
<s:complexType name="AuthHeader">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="UserId" type="s:string"/>
<s:element minOccurs="1" maxOccurs="1" name="RegGuid" type="s1:guid"/>
</s:sequence>
<s:anyAttribute/>
</s:complexType>
</s:schema>
<s:schema elementFormDefault="qualified" targetNamespace="http://microsoft.com/wsdl/types/">
<s:simpleType name="guid">
<s:restriction base="s:string">
<s:pattern value="[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"/>
</s:restriction>
</s:simpleType>
</s:schema>
</wsdl:types>
<wsdl:message name="HelloWorldSoapIn">
<wsdl:part name="parameters" element="tns:HelloWorld"/>
</wsdl:message>
<wsdl:message name="HelloWorldSoapOut">
<wsdl:part name="parameters" element="tns:HelloWorldResponse"/>
</wsdl:message>
<wsdl:message name="HelloWorldAuthHeader">
<wsdl:part name="AuthHeader" element="tns:AuthHeader"/>
</wsdl:message>
<wsdl:portType name="WebService1Soap">
<wsdl:operation name="HelloWorld">
<wsdl:input message="tns:HelloWorldSoapIn"/>
<wsdl:output message="tns:HelloWorldSoapOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="WebService1Soap" type="tns:WebService1Soap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="HelloWorld">
<soap:operation soapAction="http://tempuri.org/HelloWorld" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
<soap:header message="tns:HelloWorldAuthHeader" part="AuthHeader" use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="WebService1Soap12" type="tns:WebService1Soap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="HelloWorld">
<soap12:operation soapAction="http://tempuri.org/HelloWorld" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
<soap12:header message="tns:HelloWorldAuthHeader" part="AuthHeader" use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="WebService1">
<wsdl:port name="WebService1Soap" binding="tns:WebService1Soap">
<soap:address location="http://localhost:1415/WebService1.asmx"/>
</wsdl:port>
<wsdl:port name="WebService1Soap12" binding="tns:WebService1Soap12">
<soap12:address location="http://localhost:1415/WebService1.asmx"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Was mach ich falsch? Kann mir jemand weiterhelfen?
Besten Dank im Voraus!
Zuletzt bearbeitet von einem Moderator: