开发者

Webservice Namespace problem

I have a ASP.NET webservice which is called by a Java client. The client sends a SOAP message as input but the problem is that it never reaches my webservice method. I always get null input. I used TraceListener and saw this warning which may cause the problem:

The element was not expected in this context: ... Expected elements: http://client.ns.url/:ListenerInput.

This is what the client sends:

<?xml version="1.0" encoding="utf-8"?>
<S:Envelope xmlns:S = "http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
        <ns2:Listener xmlns:ns2 = "http://client.ns.url/">
            <ListenerInput>
                <errorCode>0</errorCode>
                <errorDescription>Success</errorDescription>
                <firstPrice xsi:nil = "true" xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"/>
            </ListenerInput>
        </ns2:Listener>
    </S:Body>
</S:Envelope>

And here's my webmethod:

[System.Web.Services.WebServiceAttribute(Namespace = "http://client.ns.url/")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.Web.Services.WebServiceBindingAttribute(Name = "ListenerWebServicePortSoapBinding", Namespace = "http://client.ns.url/")]
public partial class ListenerService : System.Web.Services.WebService
{

    [System.Web.Services.WebMethodAttribute()]
    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://client.different.url/services/action/ListenerService/Listener", RequestElementName = "Listener", RequestNamespace = "http://client.ns.url/", ResponseNamespace = "http://client.ns.url/", Use = System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle = System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
    [return: System.Xml.Serialization.XmlElementAttribute("return")] 
    public ListenerResponse Listener([System.Xml.Serialization.XmlElementAttribute("ListenerInput")]ListenerInput listenerInput)
    {
..

This is the input class:

[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://client.ns.url")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.42")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
public partial class ListenerInput
{
    public int errorCode;
    public string errorDescription;
    public float? firstPrice;
}

What should I do to solve this? Here's the some of the trace log:

Calling IHttpHandler.ProcessRequest
    Caller: System.Web.Services.Protocols.SyncSessionlessHandler#47754503::ProcessRequest()
    Request Host Address: xxx
    Request Url: [POST] http:/my.website/Listener.asmx
..
Calling XmlSerializer [Read Request]
    Method: Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer#53218107::Deserialize(System.Web.Services.Protocols.SoapServerProtocol+SoapEnvelopeReader#4153573=.., (null))
    Caller: System.Web.Services.Protocols.SoapServerProtocol#51389704::ReadParameters()
...
The element was not expected in this context: <ListenerInput>..</ListenerInput>. Expected el开发者_运维百科ements: http://client.ns.url/:ListenerInput.
...
Return from XmlSerializer [Read Request]
    Caller: System.Web.Services.Protocols.SoapServerProtocol#51389704::ReadParameters()
...
 Calling ListenerResponse Listener(ListenerInput)
    Method: ListenerService#64693151::Listener((null))
    Caller: System.Web.Services.Protocols.SyncSessionlessHandler#47754503::Invoke()


Solved the problem. I was using client's namespace address when I should be using my own. Changed this:

[System.Web.Services.WebServiceBindingAttribute(Name = "ListenerWebServicePortSoapBinding", Namespace = "http://client.ns.url/")]
public partial class ListenerService : System.Web.Services.WebService

to this:

[System.Web.Services.WebServiceBindingAttribute(Name = "ListenerWebServicePortSoapBinding", Namespace = "http://my.ns.url/")]
public partial class ListenerService : System.Web.Services.WebService
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜