.NET consume php web service - c#

I have php web service. and can consume it from php client.
But problem occurs when i try call from c# win app.
Do you have any ideas..
Problem is it returns null, also i cannot see it from object browser
My wsdl file
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:ns0="http://1sunucu.com" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://1sunucu.com">
<wsdl:types>
<xs:schema xmlns:ns="http://1sunucu.com" xmlns:ns1="http://1sunucu.com/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://HighSchool.edu">
<xs:element name="ExamResult">
<xs:complexType>
<xs:sequence>
<xs:element name="kullaniciKod" type="xs:string"/>
<xs:element name="sifre" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ExamResultResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="result" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="ExamResultRequest">
<wsdl:part name="parameters" element="ns0:ExamResult"/>
</wsdl:message>
<wsdl:message name="ExamResultResponse">
<wsdl:part name="parameters" element="ns0:ExamResultResponse"/>
</wsdl:message>
<wsdl:portType name="ExamResultPortType">
<wsdl:operation name="ExamResult">
<wsdl:input message="ns0:ExamResultRequest" wsaw:Action="urn:ExamResult"/>
<wsdl:output message="ns0:ExamResultResponse" wsaw:Action="urn:ExamResultResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ExamResultSOAP12Binding" type="ns0:ExamResultPortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="ExamResult">
<soap12:operation soapAction="urn:ExamResult" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ExamResult">
<wsdl:port name="ExamResultSOAP12port_http" binding="ns0:ExamResultSOAP12Binding">
<soap12:address location="http://localhost/ws/soap-server.php"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

Thanks to SoapUi. i have solved the problem...There was a response error in php server

Related

WCF- service method fails to reference entity as parameter

I have the attached WSDL and i need to generate client stubs using Visual Studio 2013, WCF and .NET 4.5. Instead of the expected parameter BoolExpression in the signature, i get an object[] parameter.The generated getResourceList service method looks like this:
public TestFieldSOAP.ServiceReference1.ResourceWrapper[] getResourceList(long arg0, long arg1, object[] arg2, object[] arg3)
while it should look like this:
public TestFieldSOAP.ServiceReference1.ResourceWrapper[] getResourceList(long arg0, long arg1, BoolExpression be, object[] arg3)
In a few words, the entity BoolExpression is defined in the schema, but is not referenced as parameter in the method. I have been researching a lot on WSDLs and XSDs, but i haven't found the answer so far.
Any ideas?
The WSDL
<?xml version="1.0" ?>
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://ResourceManagementBasic.webservices.xxx.com/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:ns3="http://schemas.xmlsoap.org/soap/http"
xmlns:ns2="http://security.lowLevel.hello.webservices.xxx.com/"
xmlns:ns1="http://ResourceManagement.hello.xxx.com/" name="WSResourceAdmin_v15Service"
targetNamespace="http://ResourceManagementBasic.webservices.xxx.com/">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://hello.xxx.com/" elementFormDefault="qualified"
targetNamespace="http://hello.xxx.com/" version="1.0">
<xs:complexType name="BoolExpression">
<xs:sequence>
<xs:element maxOccurs="unbounded" name="expressions"
nillable="true" type="xs:anyType"></xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="AttributeOperatorValueExpression">
<xs:complexContent>
<xs:extension base="tns:BoolExpression">
<xs:sequence>
<xs:element name="attribute" nillable="true" type="xs:string"></xs:element>
<xs:element name="operator" nillable="true" type="xs:string"></xs:element>
<xs:element name="value" nillable="true" type="xs:anyType"></xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="ANDExpression">
<xs:complexContent>
<xs:extension base="tns:BoolExpression">
<xs:sequence></xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="Wrapper">
<xs:sequence>
<xs:element maxOccurs="unbounded" name="value" nillable="true"
type="xs:anyType"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://Wrappers.hello.xxx.com" version="1.0">
<xs:complexType name="ResourceWrapper">
<xs:sequence>
<xs:element form="qualified" name="Resource" nillable="true" type="xs:long"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://ResourceManagementBasic.webservices.xxx.com/"
xmlns:ns6="http://Wrappers.hello.xxx.com" xmlns:ns1="http://hello.xxx.com/"
attributeFormDefault="unqualified" elementFormDefault="unqualified"
targetNamespace="http://ResourceManagementBasic.webservices.xxx.com/">
<xs:import namespace="http://hello.xxx.com/"></xs:import>
<xs:import namespace="http://Wrappers.hello.xxx.com"></xs:import>
<xs:element name="getResourceList" type="tns:getResourceList"></xs:element>
<xs:element name="getResourceListResponse" type="tns:getResourceListResponse"></xs:element>
<xs:complexType name="getResourceListResponse">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="return"
type="ns6:ResourceWrapper"></xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="getResourceList">
<xs:sequence>
<xs:element minOccurs="0" name="arg0" type="xs:long"></xs:element>
<xs:element minOccurs="0" name="arg1" type="xs:long"></xs:element>
<xs:element minOccurs="0" name="arg2" type="ns1:BoolExpression" form="qualified"></xs:element>
<xs:element maxOccurs="unbounded" minOccurs="0" name="arg3" type="xs:anyType"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="getResourceListResponse">
<wsdl:part element="tns:getResourceListResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getResourceList">
<wsdl:part element="tns:getResourceList" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="WSResourceAdmin_v15">
<wsdl:operation name="getResourceList">
<wsdl:input message="tns:getResourceList" name="getResourceList">
</wsdl:input>
<wsdl:output message="tns:getResourceListResponse" name="getResourceListResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="WSResourceAdmin_v15ServiceSoapBinding"
type="tns:WSResourceAdmin_v15">
<soap12:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"></soap12:binding>
<wsdl:operation name="getResourceList">
<soap12:operation soapAction="" style="document"></soap12:operation>
<wsdl:input name="getResourceList">
<soap12:body use="literal"></soap12:body>
</wsdl:input>
<wsdl:output name="getResourceListResponse">
<soap12:body use="literal"></soap12:body>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="WSResourceAdmin_v15Service">
<wsdl:port binding="tns:WSResourceAdmin_v15ServiceSoapBinding"
name="WSResourceAdmin_v15Port">
<soap12:address
location="xxx"></soap12:address>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Here is also the method signature of the generated getResource method stub
[System.Xml.Serialization.XmlArrayItemAttribute("expressions", Namespace="http://hello.xxx.com/")]
public object[] arg2 {
EDIT 8th of Feb 2016
It seems like valid fixed is right: the object[] is a result of the anyType sequence defined within the BoolExpression type. I read that removing the import to the namespace of the BoolExpression will cause the svcutil generator to include the BoolExpression as a parameter in the generated method. Would this work? Or would you propose to use another workaround? I cannot test my assumption at the time since i am running from one .NET bug to the other
Its how wsdl defines it.
Elements that are type="**:anyType" are mapped to Object objects.

Convert WSE3 Web Service Client Code to WCF

Convert WSE3 Web Service Client Code to WCF
Hi. It would be much appreciated if an expert could be able to convert the following WSE3 web service client code to some working(well as much as possible) WCF code(preferable with configuration in code and entire code as short as can be) please? I've seen some examples using the ChannelFactory class but there may be a cleaner/shorter way.
The 3rd Party web service being called is: HTTPS, EndPoint is ASMX file, SOAP 1.1, and using ws-security. The working WSE3 code is:
Dim ExpCertificate As New X509Certificate2
ExpCertificate = New X509Certificate2("<pfx file>", "<password>")
Dim waspservice As New TokenService
waspservice.ClientCertificates.Add(ExpCertificate)
waspservice.Url = "https://somesite.asmx"
Dim res As String = waspservice.STS("<WASPAuthenticationRequest><ApplicationName>Example Client</ApplicationName><AuthenticationLevel>CertificateAuthentication</AuthenticationLevel><AuthenticationParameters/></WASPAuthenticationRequest>")
Response.Write(res & vbCrLf & vbCrLf)
An example soap request is:
<wsse:Security>
<wsu:Timestampwsu:Id="Timestamp-2b27a32b-ca9c-4405-b377-4444f63c8f29">
<wsu:Created>2011-02-20T16:36:54Z</wsu:Created>
<wsu:Expires>2011-02-20T16:41:54Z</wsu:Expires>
</wsu:Timestamp>
<wsse:BinarySecurityToken ValueType="CompanyWASP" EncodingType="wsse:Base64Binary" wsu:Id="SecurityToken-f64439f9-c12c-4d09-ac3d-fc478ad19775">MjAtRTctQ0YtMTUtN0EtODEtNTk.</wsse:BinarySecurityToken>
</wsse:Security>
</soap:Header>
<soap:Body>
<! -- SOAP content for the service call -- >
</soap:Body>
The WSDL is:
<wsdl:definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://www.uk.company.com/WASP/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" targetNamespace="http://www.uk.company.com/WASP/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://www.uk.company.com/WASP/">
<s:element name="STS">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="authenticationBlock" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="STSResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="STSResult" 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="STSSoapIn">
<wsdl:part name="parameters" element="tns:STS" />
</wsdl:message>
<wsdl:message name="STSSoapOut">
<wsdl:part name="parameters" element="tns:STSResponse" />
</wsdl:message>
<wsdl:message name="STSHttpGetIn">
<wsdl:part name="authenticationBlock" type="s:string" />
</wsdl:message>
<wsdl:message name="STSHttpGetOut">
<wsdl:part name="Body" element="tns:string" />
</wsdl:message>
<wsdl:message name="STSHttpPostIn">
<wsdl:part name="authenticationBlock" type="s:string" />
</wsdl:message>
<wsdl:message name="STSHttpPostOut">
<wsdl:part name="Body" element="tns:string" />
</wsdl:message>
<wsdl:portType name="TokenServiceSoap">
<wsdl:operation name="STS">
<wsdl:input message="tns:STSSoapIn" />
<wsdl:output message="tns:STSSoapOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:portType name="TokenServiceHttpGet">
<wsdl:operation name="STS">
<wsdl:input message="tns:STSHttpGetIn" />
<wsdl:output message="tns:STSHttpGetOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:portType name="TokenServiceHttpPost">
<wsdl:operation name="STS">
<wsdl:input message="tns:STSHttpPostIn" />
<wsdl:output message="tns:STSHttpPostOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="TokenServiceSoap" type="tns:TokenServiceSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
<wsdl:operation name="STS">
<soap:operation soapAction="http://www.uk.company.com/WASP/STS" 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="TokenServiceHttpGet" type="tns:TokenServiceHttpGet">
<http:binding verb="GET" />
<wsdl:operation name="STS">
<http:operation location="/STS" />
<wsdl:input>
<http:urlEncoded />
</wsdl:input>
<wsdl:output>
<mime:mimeXml part="Body" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="TokenServiceHttpPost" type="tns:TokenServiceHttpPost">
<http:binding verb="POST" />
<wsdl:operation name="STS">
<http:operation location="/STS" />
<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="TokenService">
<documentation xmlns="http://schemas.xmlsoap.org/wsdl/">company Token Service</documentation>
<wsdl:port name="TokenServiceSoap" binding="tns:TokenServiceSoap">
<soap:address location="https://secure.authenticator.uat.uk.company.com/WaspAuthenticator/TokenService.asmx" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Generate proxy class either of using
wsdl.exe OR by adding service reference in visual studio. That will create required proxy.
Proxy will have methods which you want to call. Pass in required parameters and you should be good.

Cannot import WSDL service "targetNamespace 'urn:webservice' not found'

The last couple of hours I've been struggling with importing a WSDL webservice into Visual Studio 2010. Slowly I've been struggling through my WSDL, solving other problems untill I encountered this one:
Warning 1 Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension:
System.ServiceModel.Description.XmlSerializerMessageContractImporter
Error: Schema with target namespace 'urn:WebService' could not be found.
XPath to Error Source:
//wsdl:definitions[#targetNamespace='urn:WebService']/wsdl:portType[#name='DataPort']
C:\* blablabla *\WeGotchaService\Reference.svcmap 1 1 Gotcha!
I've tried every tiny little thing Google could provide me with including:
Disable 'Reuse types in referenced assemblies'
Set Collection type to system.collections.generic.list
Changing a large part of the attributes back and forth.
Copying a WSDL file from someone else, just to see if it would work (it didn't)
Here is my .wsdl file:
<?xml version="1.0"?>
<definitions
name="WebService"
targetNamespace="urn:WebService"
xmlns:tns="urn:WebService"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="GetData">
<xsd:element name="getCustomerID" type="xsd:int" />
<xsd:element name="DataResponse" type="xsd:string" />
</xsd:schema>
</types>
<message name="doGetCustomerID">
<part name="ID" type="tns:getCustomerID" />
</message>
<message name="doDataResponse">
<part name="return" type="tns:DataResponse" />
</message>
<portType name="DataPort">
<operation name="getData">
<input message="tns:doGetCustomerID" />
<output message="tns:doDataResponse" />
</operation>
</portType>
<binding name="DataBinding" type="tns:DataPort">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="getData">
<soap:operation soapAction="urn:getDataAction" />
<input>
<soap:body use="encoded" namespace="urn:GetData" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</input>
<output>
<soap:body use="encoded" namespace="urn:GetData" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</output>
</operation>
</binding>
<service name="WeGotchaService">
<port name="DataPort" binding="tns:DataBinding">
<soap:address location="http://localhost/weGotcha/servicehandler.php" />
</port>
</service>
</definitions>
Servicehandler.php
<?php
if(!extension_loaded("soap"))
{
dl("php_soap.dll");
}
ini_set("soap.wsdl_cache_enabled", "0");
$server = new SoapServer("getPersonen.wsdl");
function getData($persoon_id)
{
mysql_connect("localhost", "root", "");
mysql_select_db('gotcha_dbtemplate');
$sql = "SELECT * FROM lessen";
$sql = mysql_query($sql);
while($row = mysql_fetch_array($sql))
{
$result[] = $row;
}
mysql_close();
return $result;
}
$server->addFunction("getData");
$server->handle();
?>
I don't know how to fix this. There are some other errors but these are due to the fact that it has trouble importing the portType (binding import error because portType is not okay, port error because dependant on binding)
I hope someone knows what the problem is, I don't :(
Thanks.
Update: my test.php does work okay and it does output the results from the getData method.
I've changed so much I can't exactly remember, now it works:
<?xml version="1.0"?>
<definitions xmlns:tns="http://localhost/weGotcha/servicehandler/wsdl_service.wsdl" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" name="WebService" targetNamespace="http://localhost/weGotcha/servicehandler/wsdl_service.wsdl">
<types>
<xs:schema elementFormDefault="qualified" targetNamespace="http://localhost/weGotcha/servicehandler/wsdl_service.wsdl" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://localhost/weGotcha/servicehandler/wsdl_service.wsdl">
<xsd:element name="getCustomerID" type="xsd:int"/>
<xs:complexType name="Persoon">
<xs:sequence>
<xs:element name="ID" type="xsd:int"/>
<xs:element name="Voornaam" type="xsd:string"/>
<xs:element name="Achternaam" type="xsd:string"/>
<xs:element name="Adres" type="xsd:string"/>
<xs:element name="Postcode" type="xsd:string"/>
<xs:element name="Woonplaats" type="xsd:string"/>
<xs:element name="Email_adres" type="xsd:string"/>
<xs:element name="Telefoonnummer" type="xsd:string"/>
<xs:element name="CBR_Kandidaatnummer" type="xsd:string"/>
<xs:element name="Rijbewijs" type="xsd:int"/>
<xs:element name="Laatste_keer_bewerkt" type="xsd:dateTime"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="PersoonList">
<xs:complexContent>
<xs:restriction base="soapenc:Array">
<xs:sequence>
<xs:element name="Persoon" type="tns:Persoon" maxOccurs="unbounded"/>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:schema>
</types>
<message name="doGetCustomerID">
<part name="CustomerID" type="xsd:int"/>
</message>
<message name="doGetPersoonDataResponse">
<part name="return" type="tns:PersoonList"/>
</message>
<portType name="DataPort">
<operation name="getPersoonData">
<input message="tns:doGetCustomerID"/>
<output message="tns:doGetPersoonDataResponse"/>
</operation>
</portType>
<binding name="DataBinding" type="tns:DataPort">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getPersoonData">
<soap:operation soapAction="urn:getDataAction"/>
<input>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:GetData"/>
</input>
<output>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:GetData"/>
</output>
</operation>
</binding>
<service name="WeGotchaService">
<port name="DataPort" binding="tns:DataBinding">
<soap:address location="http://localhost/weGotcha/servicehandler/servicehandler.php"/>
</port>
</service>

SoapSender & SoapEnvelope

enter code here I am trying to call a web service from a c# client. I found out that we can use SoapSender and SoapReceiver classes. please refer below for web service's WSDL
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://test/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="WelcomeService" targetNamespace="http://test/">
<types>
<xs:schema xmlns:tns="http://test/" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://test/" version="1.0">
<xs:element name="WelcomeMessage" type="tns:WelcomeMessage"/>
<xs:element name="WelcomeMessageResponse" type="tns:WelcomeMessageResponse"/>
<xs:complexType name="WelcomeMessage">
<xs:sequence>
<xs:element minOccurs="0" name="message" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="WelcomeMessageResponse">
<xs:sequence/>
</xs:complexType>
</xs:schema>
</types>
<message name="Welcome_WelcomeMessageResponse">
<part element="tns:WelcomeMessageResponse" name="WelcomeMessageResponse"/>
</message>
<message name="Welcome_WelcomeMessage">
<part element="tns:WelcomeMessage" name="WelcomeMessage"/>
</message>
<portType name="Welcome">
<operation name="WelcomeMessage" parameterOrder="WelcomeMessage">
<input message="tns:Welcome_WelcomeMessage"/>
<output message="tns:Welcome_WelcomeMessageResponse"/>
</operation>
</portType>
<binding name="WelcomeBinding" type="tns:Welcome">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="WelcomeMessage">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="WelcomeService">
<port binding="tns:WelcomeBinding" name="WelcomePort">
<soap:address location="http://127.0.0.1:8080/SoapSeam/Welcome"/>
</port>
</service>
</definitions>
I am having hard time to figure out how to populate Soap envelope object.
You must have found old or bad information on the web. See How to Consume a Web Service for current information.
Also, see wcf. WCF is the technology you should use to work with SOAP web services.

Axis2 always receives null parameters even if SOAP request is sent correctly?

I have a web-service written in Java, hosted on an Axis2 / Tomcat / Apache server. My client software is written in C#.
I have had a few irritating problems with the way java2wsdl generates the wsdl file, which did cause me a few headaches early on, but with this problem I am completely stumped.
Basically what is happening is that the client sees the web service fine, and sends a perfectly valid (or at least, it looks valid to me) SOAP request with parameters.
On the server, the correct web method is executed, but the parameters are all null. My web service detects this and builds up a response, which the client receives and understands perfectly well.
My hunch is that Axis2 is falling flat on its face somewhere, but given the headaches I have had with java2wsdl, perhaps all I need is a change in my wsdl file.
Here is the wsdl file:
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:axis2="http://stws/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:ns0="http://stws/xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://stws/">
<wsdl:types>
<xs:schema xmlns:ns="http://stws/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://stws/xsd">
<xs:element name="GetGroups">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="serialcode" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetGroupsResponse">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="ns0:Group"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="Group">
<xs:sequence>
<xs:element minOccurs="0" name="ID" type="xs:int"/>
<xs:element minOccurs="0" name="Name" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="GetMessages">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="serialcode" nillable="true" type="xs:string"/>
<xs:element maxOccurs="unbounded" minOccurs="0" name="groupids" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetMessagesResponse">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="return" nillable="true" type="ns0:Message"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="Message">
<xs:sequence>
<xs:element minOccurs="0" name="date" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="group" type="xs:int"/>
<xs:element minOccurs="0" name="messageID" type="xs:int"/>
<xs:element minOccurs="0" name="text" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="GetMessagesRequest">
<wsdl:part name="parameters" element="ns0:GetMessages"/>
</wsdl:message>
<wsdl:message name="GetMessagesResponse">
<wsdl:part name="parameters" element="ns0:GetMessagesResponse"/>
</wsdl:message>
<wsdl:message name="GetGroupsRequest">
<wsdl:part name="parameters" element="ns0:GetGroups"/>
</wsdl:message>
<wsdl:message name="GetGroupsResponse">
<wsdl:part name="parameters" element="ns0:GetGroupsResponse"/>
</wsdl:message>
<wsdl:portType name="MyProjectPortType">
<wsdl:operation name="GetMessages">
<wsdl:input message="axis2:GetMessagesRequest" wsaw:Action="urn:GetMessages"/>
<wsdl:output message="axis2:GetMessagesResponse" wsaw:Action="urn:GetMessagesResponse"/>
</wsdl:operation>
<wsdl:operation name="GetGroups">
<wsdl:input message="axis2:GetGroupsRequest" wsaw:Action="urn:GetGroups"/>
<wsdl:output message="axis2:GetGroupsResponse" wsaw:Action="urn:GetGroupsResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="MyProjectSOAP11Binding" type="axis2:MyProjectPortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="GetMessages">
<soap:operation soapAction="urn:GetMessages" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetGroups">
<soap:operation soapAction="urn:GetGroups" 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="MyProjectSOAP12Binding" type="axis2:MyProjectPortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="GetMessages">
<soap12:operation soapAction="urn:GetMessages" style="document"/>
<wsdl:input>
<soap12:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap12:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetGroups">
<soap12:operation soapAction="urn:GetGroups" 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="MyProjectHttpBinding" type="axis2:MyProjectPortType">
<http:binding verb="POST"/>
<wsdl:operation name="GetMessages">
<http:operation location="MyProject/GetMessages"/>
<wsdl:input>
<mime:content type="text/xml" part="GetMessages"/>
</wsdl:input>
<wsdl:output>
<mime:content type="text/xml" part="GetMessages"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="GetGroups">
<http:operation location="MyProject/GetGroups"/>
<wsdl:input>
<mime:content type="text/xml" part="GetGroups"/>
</wsdl:input>
<wsdl:output>
<mime:content type="text/xml" part="GetGroups"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="MyProject">
<wsdl:port name="MyProjectSOAP11port_http" binding="axis2:MyProjectSOAP11Binding">
<soap:address location="http://localhost:8080/axis2/services/MyProject"/>
</wsdl:port>
<wsdl:port name="MyProjectSOAP12port_http" binding="axis2:MyProjectSOAP12Binding">
<soap12:address location="http://localhost:8080/axis2/services/MyProject"/>
</wsdl:port>
<wsdl:port name="MyProjectHttpport" binding="axis2:MyProjectHttpBinding">
<http:address location="http://localhost:8080/axis2/services/MyProject"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
And here is a sample request and response:
Request:
<?xml version='1.0' encoding='utf-8'?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<GetGroups xmlns="http://stws/xsd">
<serialcode>123456-654321</serialcode>
</GetGroups>
</soap:Body>
</soap:Envelope>
Response
<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<GetGroupsResponse xmlns="http://stws/xsd">
<return>
<ID>-101</ID>
<name>ERROR: Empty Serial</name>
</return>
</GetGroupsResponse>
</soapenv:Body>
</soapenv:Envelope>
Does anybody have any idea what could be going wrong?
The error message in the response can only be sent when the serialcode parameter in the request is empty / null, so I'm guessing there is something wrong with how Axis2 is reading my parameters.
============================================================
How to fix this:
This is in response to Aldo's request for more information about how I fixed this problem.
I am unsure of why this fix works - perhaps it is just a bug in Axis2 or something. Either way, YMMV as I don't know whether the problem was caused by my setup or something else. All I can say is that by doing the following, everything started working.
Anyway, the auto-generated WSDL file creates complex-element types for web requests and their parameters, even when the only parameters are simple types such as strings or integers. What I did was go through and create the correct simple-type tags for parameters (such as 'serialcode' or 'date-string'), then replace the references to the complex types elsewhere in the WSDL file with references to the simple types.
An example is below:
Auto Generated WSDL method and parameters
<!--Requests-->
<wsdl:message name="RegisterClientRequest">
<wsdl:part name="parameters" element="ns0:RegisterClient"/>
</wsdl:message>
<wsdl:message name="GetGroupsRequest">
<wsdl:part name="parameters" element="ns0:GetGroups"/>
</wsdl:message>
<!--Parameters-->
<xs:element name="RegisterClient">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="serialcode" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetGroups">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="serialcode" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
Basically what you should do is discard the auto-generated parameters and create simple-types. You then modify the 'request' tags to use 'type' rather than 'element', and use your newly created simple-types.
Modified / Fixed WSDL
<!--Requests-->
<wsdl:message name="RegisterClientRequest">
<wsdl:part name="parameters" type="ns0:SerialCode"/>
</wsdl:message>
<wsdl:message name="GetGroupsRequest">
<wsdl:part name="parameters" type="ns0:SerialCode"/>
</wsdl:message>
<!--Parameters-->
<xs:simpleType name="SerialCode">
<xs:restriction base="xs:string"/>
</xs:simpleType>
Obviously it depends on what your parameters actually are. In my case they are all standard simple types such as strings and integers. If you are passing more than one parameter, you may need to play around by retaining the auto-generated elements but making sure that the element refers to simple types rather than just including the type attribute as 'xs:string' or something of that nature.
Apologies I can't be more clear on this, but as I said earlier - I don't know why this works.
One final thing: By removing the 'element' reference attribute in the request tags - you may receive a parser warning in your Axis2 logs. So far this has not caused me any problems, but it's something to be aware of in case you run into trouble.
I solved this issue by going through my WSDL file and, wherever possible, breaking down elements into their simple type counterparts and updating the references between the XML elements accordingly.
I am unsure why this works, but it has solved my problem anyway.
If you had a complex attribute this is how you could do it
Before
<xs:element name="getMyMenu">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="number" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="var2" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="var3" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="var4" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
After
<xs:complexType name="getMyMenu">
<xs:sequence>
<xs:element minOccurs="0" name="number" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="var2" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="var3" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="var4" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
And then change this
<wsdl:message name="getMyMenuRequest">
<wsdl:part name="parameters" type="ns0:getUssdMenu"/>
</wsdl:message>
To
<wsdl:message name="getMyMenuRequest">
<wsdl:part name="parameters" type="ns:getUssdMenu"/>
</wsdl:message>
That should be it! It did it for me....
This is just a hunch, but maybe you're having a namespace issue. If you focus on this part of the wsdl, notice that your parameter has an "ns0" namespace for the elements, but in your operations defined later, it looks like you're using an "axis2" namespace. With all of my Axis2 generated WSDLs, these two namespaces are the same.
<wsdl:message name="GetMessagesRequest">
<wsdl:part name="parameters" element="ns0:GetMessages"/>
</wsdl:message>
<wsdl:message name="GetMessagesResponse">
<wsdl:part name="parameters" element="ns0:GetMessagesResponse"/>
</wsdl:message>
<wsdl:message name="GetGroupsRequest">
<wsdl:part name="parameters" element="ns0:GetGroups"/>
</wsdl:message>
<wsdl:message name="GetGroupsResponse">
<wsdl:part name="parameters" element="ns0:GetGroupsResponse"/>
</wsdl:message>
<wsdl:portType name="MyProjectPortType">
<wsdl:operation name="GetMessages">
<wsdl:input message="axis2:GetMessagesRequest" wsaw:Action="urn:GetMessages"/>
<wsdl:output message="axis2:GetMessagesResponse" wsaw:Action="urn:GetMessagesResponse"/>
</wsdl:operation>
<wsdl:operation name="GetGroups">
<wsdl:input message="axis2:GetGroupsRequest" wsaw:Action="urn:GetGroups"/>
<wsdl:output message="axis2:GetGroupsResponse" wsaw:Action="urn:GetGroupsResponse"/>
</wsdl:operation>
</wsdl:portType>
Another thing you can check is to verify that the wsdl you got from java2wsdl is the same that is generated by axis2. Unless you have changed the default setting of "useoriginalwsdl" in your services.xml, these wsdls can "look" different. I never had to perform a java2wsdl manually to get my webservice to function correctly...
So basically, hit your service URL in a browser and tack on the ?wsdl at the end of the url...you should get a wsdl for comparison sake.
Also, have your client generate stubs from the server's wsdl instead of one that is generated by java2wsdl (assuming you originally used the wsdl from java2wsdl). Again, we never had to pass a manually generated wsdl around to anyone...they just simply consumed the dynamically generated one from the server...
Have you tried to send a request like this?
<?xml version='1.0' encoding='utf-8'?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<request>
<GetGroups xmlns="http://stws/xsd">
<serialcode>123456-654321</serialcode>
</GetGroups>
</request>
</soap:Body>
</soap:Envelope>
All my requests have the request tag before the actual request parameters.
try this:
123456-654321
Put xmlns="" into the parameter tag. I have the same problem and I don't know what I can modify in order to receive the parameter whitout the xmlnx.
I have another fix. I eventually discovered that if I didn't let my IDE (Netbeans 6.8) generate the WSDL then the web service worked. Alternatively if I deleted it, unticked the generate option and re-deployed then it worked.
Comparing a Netbeans generated WSDL to a server generated one I noticed the following differences :
xmlns:ns0="http:///xsd"
target namespace at the end of the wsdl:definitions tag had a trailing slash
ns0 used to choose the elements that make up the wsdl:message tag
Removing all these and re-deploying worked!

Categories

Resources