Salve a tutti,
ho la necessità di realizzare un server di mock, per il testing di un servizio che risiede su intranet (inaccessibile dalla mia postazione di sviluppo).
Dispongo del seguente WSDL (o meglio, una sua versione semplificata):
codice:
<?xml version="1.0" encoding="utf-8"?>
<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:s0="http://tempuri.org/type"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:tns="http://tempuri.org/wsdl/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="http://tempuri.org/wsdl/"
name="APPWS">
<message name="User.DoStuff">
<part name="param" type="s:string"/>
</message>
<message name="User.DoStuffResponse">
<part name="Result" type="s:string"/>
</message>
<message name="Group.DoStuff">
<part name="param" type="s:string"/>
</message>
<message name="Group.DoStuffResponse">
<part name="Result" type="s:string"/>
</message>
<portType name="UserSoapPort">
<operation name="DoStuff" parameterOrder="param">
<input message="tns:User.DoStuff"/>
<output message="tns:User.DoStuffResponse"/>
</operation>
</portType>
<portType name="GroupSoapPort">
<operation name="DoStuff" parameterOrder="param">
<input message="tns:Group.DoStuff"/>
<output message="tns:Group.DoStuffResponse"/>
</operation>
</portType>
<binding name="UserSoapBinding" type="tns:UserSoapPort">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<stk:binding preferredEncoding="UTF-8" xmlns:stk="http://schemas.microsoft.com/soap-toolkit/wsdl-extension"/>
<operation name="DoStuff">
<soap:operation soapAction="http://tempuri.org/action/User.DoStuff"/>
<input>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://tempuri.org/message/"/>
</input>
<output>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://tempuri.org/message/"/>
</output>
</operation>
</binding>
<binding name="GroupSoapBinding" type="tns:GroupSoapPort">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<stk:binding preferredEncoding="UTF-8" xmlns:stk="http://schemas.microsoft.com/soap-toolkit/wsdl-extension"/>
<operation name="DoStuff">
<soap:operation soapAction="http://tempuri.org/action/Group.DoStuff"/>
<input>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://tempuri.org/message/"/>
</input>
<output>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://tempuri.org/message/"/>
</output>
</operation>
</binding>
<service name="APPWS">
<port name="UserSoapPort" binding="tns:UserSoapBinding">
<soap:address location="http://example.com/path/to/appws.asmx"/>
</port>
<port name="GroupSoapPort" binding="tns:GroupSoapBinding">
<soap:address location="http://example.com/path/to/appws.asmx"/>
</port>
</service>
</definitions>
E ho utilizzato il comando wsdl.exe per generare le interfacce del servizio:
codice:
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.6.81.0")]
[System.Web.Services.WebServiceBindingAttribute(Name="UserSoapBinding", Namespace="http://tempuri.org/wsdl/")]
public interface IUserSoapBinding {
[System.Web.Services.WebMethodAttribute()]
[System.Web.Services.Protocols.SoapRpcMethodAttribute("http://tempuri.org/action/User.DoStuff", RequestNamespace="http://tempuri.org/message/", ResponseNamespace="http://tempuri.org/message/")]
[return: System.Xml.Serialization.SoapElementAttribute("Result")]
string DoStuff(string param);
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "4.6.81.0")]
[System.Web.Services.WebServiceBindingAttribute(Name="GroupSoapBinding", Namespace="http://tempuri.org/wsdl/")]
public interface IGroupSoapBinding {
[System.Web.Services.WebMethodAttribute()]
[System.Web.Services.Protocols.SoapRpcMethodAttribute("http://tempuri.org/action/Group.DoStuff", RequestNamespace="http://tempuri.org/message/", ResponseNamespace="http://tempuri.org/message/")]
[return: System.Xml.Serialization.SoapElementAttribute("Result")]
string DoStuff(string param);
}
Che ho successivamente implementato:
codice:
public class UserSoapBinding : IUserSoapBinding
{
[return: SoapElement("Result")]
public string DoStuff(string param)
{
return "User: " + param;
}
}
public class GroupSoapBinding : IGroupSoapBinding
{
[return: SoapElement("Result")]
public string DoStuff(string param)
{
return "Group: " + param;
}
}
Ho quindi pensato di realizzare un nuovo progetto WPF, al quale ho successivamente aggiunto un servizio ASMX.
A questo punto non riesco più a proseguire: come posso replicare (esattamente) il funzionamento del servizio "originale"?
Ho provato a realizzare 2 web method che ritornano i miei due oggetti e anche a spostare le implementazioni nel servizio (come sub class). Ma non riesco proprio a ottenere lo stesso wsdl in output.
Qualche dritta?
Ringrazio in anticipo tutte le anime pie che vorranno darmi una manina