none
请教WebService命名空间前缀的问题 RRS feed

  • 问题

  • 源代码:

    Imports System.Web.Services
    Imports System.Web.Services.Protocols
    Imports System.ComponentModel
    Imports System.ServiceModel
    Imports System.Diagnostics
    Imports System.Xml.Serialization
    Imports System.Web.Services.Description


    Public Class ID
        Inherits SoapHeader
        <XmlText(GetType(String))> _
        Public ID As String
    End Class

    <SoapDocumentService(RoutingStyle:=SoapServiceRoutingStyle.RequestElement)> _
    <WebService(description:="TR069测试", name:="cwmp", Namespace:="urn:dslforum-org:cwmp-1-0")> _
    <Serializable()> _
    Public Class InformReq
        Inherits System.Web.Services.WebService

        Public Header As ID = New ID
        Public Other As SoapUnknownHeader()
        Public Class Device
            'Public Sub New()
            'End Sub
            Public Manufacturer As String
            Public OUI As String
            Public ProductClass As String
            Public SerialNumber As String
            Public Sub New()

                Manufacturer = "huawei"
                OUI = "000000"
                ProductClass = "SA000000-GPON"
                SerialNumber = "0000000000000"
            End Sub
        End Class

        Public Class EventStruct
            Public EventCode As String
            Public CommandKey As String
        End Class
        Public Class ParameterValueStruct
            Public name As String
            Public value As String
        End Class
        Public Class InformResponse
            Public MaxEnvelopes As Integer
        End Class


        <WebMethod()> _
        <SoapHeader("Header", Direction:=System.Web.Services.Protocols.SoapHeaderDirection.In, Required:=True),
          SoapDocumentMethod(requestnamespace:="urn:dslforum-org:cwmp-1-0", RequestElementName:="Inform", ResponseElementName:="InformResponse", Use:=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle:=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)> _
        Public Function Inform(ByVal DeviceId As Device, ByVal [Event]() As EventStruct, ByVal MaxEnvelopes As Integer, ByVal CurrentTime As String, ByVal RetryCount As Integer, ByVal ParameterList() As ParameterValueStruct) As <System.Xml.Serialization.XmlElementAttribute("InformResponse")> InformResponse

            Dim r As New InformResponse
            r.MaxEnvelopes = 1
            Try
                Debug.Print(Header.ID)
                Debug.Print(DeviceId.Manufacturer)

            Catch ex As Exception
                Debug.Write(ex.Message)
            End Try

            Return r
        End Function

    End Class

    问题:

    下面是客户端请求的正式报文,服务端无法获取输入参数,经过比较,发现用测试报文就可以,区别就是去掉了命名空间前缀cwmp,由于客户端是不能修改的,请问服务端需要怎么改才能正确识别输入的参数呢?

    正式报文:

    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cwmp="urn:dslforum-org:cwmp-1-0">

    <SOAP-ENV:Header>

    <cwmp:ID SOAP-ENV:mustUnderstand="1">39</cwmp:ID>

    </SOAP-ENV:Header>

    <SOAP-ENV:Body>

    <cwmp:Inform>

    <DeviceId>

    <Manufacturer>Huawei Technologies Co., Ltd</Manufacturer>

    <OUI>688F84</OUI>

    <ProductClass>SA1456C-GPON</ProductClass>

    <SerialNumber>42300688F8408AB1F</SerialNumber>

    </DeviceId>

    <Event SOAP-ENC:arrayType="cwmp:EventStruct[2]">

    <EventStruct>

    <EventCode>2 PERIODIC</EventCode>

    <CommandKey/>

    </EventStruct>

    <EventStruct>

    <EventCode>0 BOOTSTRAP</EventCode>

    <CommandKey/>

    </EventStruct>

    </Event>

    <MaxEnvelopes>1</MaxEnvelopes>

    <CurrentTime>2018-03-12T18:31:48+08:00</CurrentTime>

    <RetryCount>1847</RetryCount>

    <ParameterList SOAP-ENC:arrayType="cwmp:ParameterValueStruct[11]">

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.ManagementServer.ParameterKey</Name>

    <Value xsi:type="xsd:string">unsetCommandKey</Value>

    </ParameterValueStruct>

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.ManagementServer.ConnectionRequestURL</Name>

    <Value xsi:type="xsd:string">http://133.83.22.235:7547</Value>

    </ParameterValueStruct>

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.DeviceSummary</Name>

    <Value xsi:type="xsd:string">InternetGatewayDevice:1.1[](Baseline:1, EthernetLAN:1, WiFiLAN:1, Time:1, IPPing:1, DeviceAssociation:1)</Value>

    </ParameterValueStruct>

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.DeviceInfo.SpecVersion</Name>

    <Value xsi:type="xsd:string">1.0</Value>

    </ParameterValueStruct>

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.DeviceInfo.HardwareVersion</Name>

    <Value xsi:type="xsd:string">734.B</Value>

    </ParameterValueStruct>

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.DeviceInfo.SoftwareVersion</Name>

    <Value xsi:type="xsd:string">V3R016C00S015</Value>

    </ParameterValueStruct>

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.DeviceInfo.ProvisioningCode</Name>

    <Value xsi:type="xsd:string"/>

    </ParameterValueStruct>

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.WANDevice.1.WANConnectionDevice.5.WANIPConnection.1.ExternalIPAddress</Name>

    <Value xsi:type="xsd:string">133.83.22.235</Value>

    </ParameterValueStruct>

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANPPPConnection.1.Username</Name>

    <Value xsi:type="xsd:string">18992931985</Value>

    </ParameterValueStruct>

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.X_CT-COM_UserInfo.UserId</Name>

    <Value xsi:type="xsd:string">88888888</Value>

    </ParameterValueStruct>

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.X_CT-COM_UserInfo.UserName</Name>

    <Value xsi:type="xsd:string">919170419802583</Value>

    </ParameterValueStruct>

    </ParameterList>

    <X_OUI_AssocDevice>

    <X_OUI_DeviceInfoStruct>

    <X_OUI_DeviceManufacturerOUI/>

    <X_OUI_DeviceSerialNumber/>

    <X_OUI_DeviceProductClass/>

    </X_OUI_DeviceInfoStruct>

    </X_OUI_AssocDevice>

    </cwmp:Inform>

    </SOAP-ENV:Body>

    </SOAP-ENV:Envelope>

    测试报文:

    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:dslforum-org:cwmp-1-0">

    <SOAP-ENV:Header>

    <ID SOAP-ENV:mustUnderstand="1">39</ID>

    </SOAP-ENV:Header>

    <SOAP-ENV:Body>

    <Inform>

    <DeviceId>

    <Manufacturer>Huawei Technologies Co., Ltd</Manufacturer>

    <OUI>688F84</OUI>

    <ProductClass>SA1456C-GPON</ProductClass>

    <SerialNumber>42300688F8408AB1F</SerialNumber>

    </DeviceId>

    <Event SOAP-ENC:arrayType="cwmp:EventStruct[2]">

    <EventStruct>

    <EventCode>2 PERIODIC</EventCode>

    <CommandKey/>

    </EventStruct>

    <EventStruct>

    <EventCode>0 BOOTSTRAP</EventCode>

    <CommandKey/>

    </EventStruct>

    </Event>

    <MaxEnvelopes>1</MaxEnvelopes>

    <CurrentTime>2018-03-12T18:31:48+08:00</CurrentTime>

    <RetryCount>1847</RetryCount>

    <ParameterList SOAP-ENC:arrayType="cwmp:ParameterValueStruct[11]">

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.ManagementServer.ParameterKey</Name>

    <Value xsi:type="xsd:string">unsetCommandKey</Value>

    </ParameterValueStruct>

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.ManagementServer.ConnectionRequestURL</Name>

    <Value xsi:type="xsd:string">http://133.83.22.235:7547</Value>

    </ParameterValueStruct>

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.DeviceSummary</Name>

    <Value xsi:type="xsd:string">InternetGatewayDevice:1.1[](Baseline:1, EthernetLAN:1, WiFiLAN:1, Time:1, IPPing:1, DeviceAssociation:1)</Value>

    </ParameterValueStruct>

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.DeviceInfo.SpecVersion</Name>

    <Value xsi:type="xsd:string">1.0</Value>

    </ParameterValueStruct>

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.DeviceInfo.HardwareVersion</Name>

    <Value xsi:type="xsd:string">734.B</Value>

    </ParameterValueStruct>

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.DeviceInfo.SoftwareVersion</Name>

    <Value xsi:type="xsd:string">V3R016C00S015</Value>

    </ParameterValueStruct>

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.DeviceInfo.ProvisioningCode</Name>

    <Value xsi:type="xsd:string"/>

    </ParameterValueStruct>

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.WANDevice.1.WANConnectionDevice.5.WANIPConnection.1.ExternalIPAddress</Name>

    <Value xsi:type="xsd:string">133.83.22.235</Value>

    </ParameterValueStruct>

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANPPPConnection.1.Username</Name>

    <Value xsi:type="xsd:string">18992931985</Value>

    </ParameterValueStruct>

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.X_CT-COM_UserInfo.UserId</Name>

    <Value xsi:type="xsd:string">88888888</Value>

    </ParameterValueStruct>

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.X_CT-COM_UserInfo.UserName</Name>

    <Value xsi:type="xsd:string">919170419802583</Value>

    </ParameterValueStruct>

    </ParameterList>

    <X_OUI_AssocDevice>

    <X_OUI_DeviceInfoStruct>

    <X_OUI_DeviceManufacturerOUI/>

    <X_OUI_DeviceSerialNumber/>

    <X_OUI_DeviceProductClass/>

    </X_OUI_DeviceInfoStruct>

    </X_OUI_AssocDevice>

    </Inform>

    </SOAP-ENV:Body>

    </SOAP-ENV:Envelope>

    2018年3月12日 10:39

全部回复

  • Hi,

    >>下面是客户端请求的正式报文,服务端无法获取输入参数,经过比较,发现用测试报文就可以,区别就是去掉了命名空间前缀cwmp,

    请问无法获取参数是指什么?是服务端接收不到请求还是在服务方法上打断点,代码可以执行到,但是方法的参数是空的?

    客户端是如何生成客户端代码请求服务端的?

    对于修改SOAP Request,我建议你测试下下面的代码。

    # Capturing SOAP requests to an ASP.NET ASMX web service

    https://stackoverflow.com/questions/2624621/capturing-soap-requests-to-an-asp-net-asmx-web-service

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2018年3月13日 1:59
  • 代码可以执行到,但是方法的参数是空的.
    2018年3月13日 11:43
  • 客户端是如何生成客户端代码请求服务端的?一般来说,我们通过Add Service Reference或者wsdl.exe去生成客户端代码。不会出现参数不一致的问题。

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2018年3月14日 2:06
  • 源代码:

    Imports System.Web.Services
    Imports System.Web.Services.Protocols
    Imports System.ComponentModel
    Imports System.ServiceModel
    Imports System.Diagnostics
    Imports System.Xml.Serialization
    Imports System.Web.Services.Description

    Public Class ID
        Inherits SoapHeader
        <XmlText(GetType(String))> _
        Public ID1 As String
    End Class

    Public Class Device
        Public Manufacturer As String
        Public OUI As String
        Public ProductClass As String
        Public SerialNumber As String
    End Class
    Public Class EventStruct
        Public EventCode As String
        Public CommandKey As String
    End Class
    Public Class ParameterValueStruct
        Public Name As String
        Public Value As String
    End Class
    Public Class InformResp
        Public MaxEnvelopes As Integer
    End Class

    <WebService(description:="TR069测试", name:="cwmpService", Namespace:="urn:dslforum-org:cwmp-1-0")> _
    <WebServiceBinding(Name:="cwmpBinding", conformsto:=WsiProfiles.None)> _
    Public Class Service
        Inherits System.Web.Services.WebService
        Public Header As New ID
        Public outHeader As New ID

        <WebMethod()> _
        <SoapHeader("Header", direction:=SoapHeaderDirection.InOut),
          SoapDocumentMethod(parameterstyle:=SoapParameterStyle.Wrapped, action:="", requestnamespace:="urn:dslforum-org:cwmp-1-0", Use:=SoapBindingUse.Literal)> _
        Public Function Inform(ByVal DeviceId As Device, ByVal [Event]() As EventStruct, ByVal MaxEnvelopes As Integer, ByVal CurrentTime As String, ByVal RetryCount As Integer, ByVal ParameterList() As ParameterValueStruct) As <XmlElementAttribute("InformResponse")> InformResp
            Dim resp As New InformResp
            resp.MaxEnvelopes = 1
            Try
                Debug.Print(Header.ID1)
                outHeader = New ID
                outHeader.ID1 = 3
                Debug.Print(DeviceId.Manufacturer)
            Catch ex As Exception
                Debug.Write(ex.Message)
            End Try
            Return resp
        End Function

    End Class

    请求包

    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cwmp="urn:dslforum-org:cwmp-1-0">

    <SOAP-ENV:Header>

    <cwmp:ID SOAP-ENV:mustUnderstand="1">223</cwmp:ID>

    </SOAP-ENV:Header>

    <SOAP-ENV:Body>

    <cwmp:Inform>

    <DeviceId>

    <Manufacturer>Huawei Technologies Co., Ltd</Manufacturer>

    <OUI>688F84</OUI>

    <ProductClass>SA1456C-GPON</ProductClass>

    <SerialNumber>42300688F8408AB1F</SerialNumber>

    </DeviceId>

    <Event SOAP-ENC:arrayType="cwmp:EventStruct[1]">

    <EventStruct>

    <EventCode>2 PERIODIC</EventCode>

    <CommandKey/>

    </EventStruct>

    </Event>

    <MaxEnvelopes>1</MaxEnvelopes>

    <CurrentTime>2018-03-14T15:01:21+08:00</CurrentTime>

    <RetryCount>15396</RetryCount>

    <ParameterList SOAP-ENC:arrayType="cwmp:ParameterValueStruct[11]">

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.ManagementServer.ParameterKey</Name>

    <Value xsi:type="xsd:string">unsetCommandKey</Value>

    </ParameterValueStruct>

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.ManagementServer.ConnectionRequestURL</Name>

    <Value xsi:type="xsd:string">http://133.83.22.235:7547</Value>

    </ParameterValueStruct>

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.DeviceSummary</Name>

    <Value xsi:type="xsd:string">InternetGatewayDevice:1.1[](Baseline:1, EthernetLAN:1, WiFiLAN:1, Time:1, IPPing:1, DeviceAssociation:1)</Value>

    </ParameterValueStruct>

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.DeviceInfo.SpecVersion</Name>

    <Value xsi:type="xsd:string">1.0</Value>

    </ParameterValueStruct>

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.DeviceInfo.HardwareVersion</Name>

    <Value xsi:type="xsd:string">734.B</Value>

    </ParameterValueStruct>

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.DeviceInfo.SoftwareVersion</Name>

    <Value xsi:type="xsd:string">V3R016C00S015</Value>

    </ParameterValueStruct>

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.DeviceInfo.ProvisioningCode</Name>

    <Value xsi:type="xsd:string"/>

    </ParameterValueStruct>

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.WANDevice.1.WANConnectionDevice.5.WANIPConnection.1.ExternalIPAddress</Name>

    <Value xsi:type="xsd:string">133.83.22.235</Value>

    </ParameterValueStruct>

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.WANDevice.1.WANConnectionDevice.1.WANPPPConnection.1.Username</Name>

    <Value xsi:type="xsd:string">18992931985</Value>

    </ParameterValueStruct>

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.X_CT-COM_UserInfo.UserId</Name>

    <Value xsi:type="xsd:string">88888888</Value>

    </ParameterValueStruct>

    <ParameterValueStruct>

    <Name>InternetGatewayDevice.X_CT-COM_UserInfo.UserName</Name>

    <Value xsi:type="xsd:string">919170419802583</Value>

    </ParameterValueStruct>

    </ParameterList>

    <X_OUI_AssocDevice>

    <X_OUI_DeviceInfoStruct>

    <X_OUI_DeviceManufacturerOUI/>

    <X_OUI_DeviceSerialNumber/>

    <X_OUI_DeviceProductClass/>

    </X_OUI_DeviceInfoStruct>

    </X_OUI_AssocDevice>

    </cwmp:Inform>

    </SOAP-ENV:Body>

    </SOAP-ENV:Envelope>

    方法内无法获取输入参数!

    Debug.Print(DeviceId.Manufacturer)

    这一条提示:未将对象引用设置到对象的实例

    请帮忙分析一下是哪里的问题,^_^

    2018年3月14日 7:03
  • 你是怎么生成请求包的?

    我建议你访问你的服务界面,Invoke那个方法,查看正确的SOAP Request.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2018年3月28日 1:54