Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何向VB.NET 2008 SOAP请求添加标头?_Vb.net_Wcf_Web Services_Soap_Siebel - Fatal编程技术网

如何向VB.NET 2008 SOAP请求添加标头?

如何向VB.NET 2008 SOAP请求添加标头?,vb.net,wcf,web-services,soap,siebel,Vb.net,Wcf,Web Services,Soap,Siebel,我有一个VB.NET 2008程序,它访问由WSDL定义的Siebel web服务,并使用SOAP协议 Siebel web服务要求包含用户名、密码和会话类型的头包含在服务请求中,但该头未在WSDL中定义 因此,当我使用soapUI实用工具测试WSDL时,WSDL定义的请求如下所示: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:lov="http://www.siebel

我有一个VB.NET 2008程序,它访问由WSDL定义的Siebel web服务,并使用SOAP协议

Siebel web服务要求包含用户名、密码和会话类型的头包含在服务请求中,但该头未在WSDL中定义

因此,当我使用soapUI实用工具测试WSDL时,WSDL定义的请求如下所示:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:lov="http://www.siebel.com/xml/LOVService" xmlns:lis="http://www.siebel.com/xml/ListQuery">
<soapenv:Header/>
   <soapenv:Body>
      <lov:EAILOVGetListOfValues_Input>
         <lis:ListsQuery>
            <lis:ListQuery>
               <lis:Active>Y</lis:Active>
               <lis:LanguageCode>ENU</lis:LanguageCode>
               <lis:Type>CUT_ACCOUNT_TYPE</lis:Type>
            </lis:ListQuery>
         </lis:ListsQuery>
      </lov:EAILOVGetListOfValues_Input>
   </soapenv:Body>
</soapenv:Envelope>
…但是如何在VB发出的SOAP请求中包含此标头

我用来测试这一点的示例代码是一个带有按钮和列表框的简单表单

Public Class Form1

    Private Sub btnGetLOV_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetLOV.Click

        Dim MyService As New wsLOV.EAILOVPortClient

        Dim MyInput As New wsLOV.EAILOVGetListOfValues_Input
        Dim MyParams(0) As wsLOV.ListQuery
        Dim temp As New wsLOV.ListQuery

        Dim MyResult As New wsLOV.EAILOVGetListOfValues_Output

        temp.Active = "Y"
        temp.Type = "CUT_ACCOUNT_TYPE"
        temp.LanguageCode = "ENU"
        MyParams(0) = temp

        MyInput.ListsQuery = MyParams

        Dim MyRequest As New wsLOV.EAILOVGetListOfValuesRequest(MyInput)
        MyResult = MyService.EAILOVGetListOfValues(MyInput)


    End Sub

End Class
该代码在子例程的最后一行失败,并显示一条消息,指示请求尚未通过身份验证(错误代码:10944642错误消息:错误:入站SOAP消息-会话令牌丢失或无效或已过期),这与我在soapUI中退出包含用户名、密码、密码的标头时遇到的错误相同,和会话类型


我认为我需要将标题添加到端点(per和),但我不确定如何在VB中执行此操作。

以下是我们解决此问题的方法。键似乎是用附加的头来实例化端点,而不是在端点已经实例化之后尝试添加头

Imports System.ServiceModel.Channels
Imports System.ServiceModel

Public Class Form1

    Private Sub btnGetOrg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetOrgType.Click
        ' This example code queries the Siebel web service using the SOAP protocol for a list of
        ' Account (organization) types stored in a List of Values (LOV). The service request
        ' requires that a SOAP header be added that contains the username, password, and session
        ' type. We have to add this header because the WSDL file definition generated by Siebel
        ' does not include the header definition. The WSDL file was added to the VS2008 project as
        ' a Service Reference named "wsGetLOV"

        ' Create address headers for special services and add them to an array
        Dim addressHeader1 As AddressHeader = AddressHeader.CreateAddressHeader("UsernameToken", "http://siebel.com/webservices", "TESTUSER")
        Dim addressHeader2 As AddressHeader = AddressHeader.CreateAddressHeader("PasswordText", "http://siebel.com/webservices", "TESTPASSWORD")
        Dim addressHeader3 As AddressHeader = AddressHeader.CreateAddressHeader("SessionType", "http://siebel.com/webservices", "None")
        Dim addressHeaders() As AddressHeader = {addressHeader1, addressHeader2, addressHeader3}

        ' Endpoint address constructor with URI and address headers
        ' Replace <servername> in the following line with the name of your Siebel server.
        ' For example: http://actual-server/eai_enu...
        Dim endpointAddressWithHeaders As New EndpointAddress(New Uri("http://<servername>/eai_enu/start.swe?SWEExtSource=WebService&SWEExtCmd=Execute&WSSOAP=1"), addressHeaders)
        Dim MyService As New wsGetLOV.EAILOVPortClient("EAILOVPort", endpointAddressWithHeaders)

        Dim MyInput As New wsGetLOV.EAILOVGetListOfValues_Input
        Dim MyOutput As wsGetLOV.EAILOVGetListOfValues_Output
        Dim MyList(0) As wsGetLOV.ListQuery

        MyList(0) = New wsGetLOV.ListQuery
        MyList(0).Active = "Y"
        MyList(0).LanguageCode = "ENU"
        MyList(0).Type = "CUT_ACCOUNT_TYPE"
        MyInput.ListsQuery = MyList

        MyOutput = MyService.EAILOVGetListOfValues(MyInput)

        Dim myStrings As New List(Of String)

        ' We use nested loops because the results returned by the service is a list of
        ' lists though in our case, the result set is a list with a single item (this item
        ' being a list of multiple items)
        For Each myResultList As wsGetLOV.ListResult In MyOutput.ListsResult
            For Each myResultValue As wsGetLOV.ListValueResult In myResultList.ListValuesResult
                myStrings.Add(myResultValue.Value)
            Next
        Next

        ListBox1.DataSource = myStrings

    End Sub
End Class
导入System.ServiceModel.Channel
导入System.ServiceModel
公开课表格1
私有子btnGetOrg_Click(ByVal sender作为System.Object,ByVal e作为System.EventArgs)处理btnGetOrgType。单击
'此示例代码使用SOAP协议查询Siebel web服务以获取
'存储在值列表(LOV)中的帐户(组织)类型。服务请求
'要求添加包含用户名、密码和会话的SOAP标头
'类型。我们必须添加这个头,因为由Siebel生成的WSDL文件定义
'不包括标题定义。WSDL文件作为一个文件添加到VS2008项目中
'名为“wsGetLOV”的服务引用'
'为特殊服务创建地址头并将其添加到数组中
Dim addressHeader1 As AddressHeader=AddressHeader.CreateAddressHeader(“UsernameToken,”http://siebel.com/webservices“,“TESTUSER”)
Dim addressHeader2 As AddressHeader=AddressHeader.CreateAddressHeader(“密码文本,”http://siebel.com/webservices“,“测试密码”)
Dim addressHeader3 As AddressHeader=AddressHeader.CreateAddressHeader(“SessionType”,”http://siebel.com/webservices“,“无”)
Dim addressHeaders()作为AddressHeader={addressHeader1,addressHeader2,addressHeader3}
'具有URI和地址头的端点地址构造函数
'将下一行中的替换为Siebel服务器的名称。
例如:http://actual-server/eai_enu...
Dim endpointAddressWithHeaders作为新的EndpointAddress(新Uri(“http:///eai_enu/start.swe?SWEExtSource=WebService&SWEExtCmd=Execute&WSSOAP=1(地址标题)
将MyService设置为新的wsGetLOV.EAILOVPortClient(“EAILOVPort”,endpointAddressWithHeaders)
将MyInput设置为新的wsGetLOV.EAILOVGetListOfValues\u输入
将MyOutput设置为wsGetLOV.EAILOVGetListOfValues\u输出
将MyList(0)设置为wsGetLOV.ListQuery
MyList(0)=新建wsGetLOV.ListQuery
MyList(0)。Active=“Y”
MyList(0).LanguageCode=“ENU”
MyList(0).Type=“账户类型”
MyInput.ListsQuery=MyList
MyOutput=MyService.EAILOVGetListOfValues(MyInput)
将mystring变暗为新列表(字符串的)
'我们使用嵌套循环,因为服务返回的结果是
'列表在我们的示例中,结果集是一个包含单个项(此项)的列表
'是多个项目的列表)
对于MyOutput.ListsResult中作为wsGetLOV.ListResult的每个myResultList
对于myResultList.ListValuesResult中作为wsGetLOV.ListValueResult的每个myResultValue
添加(myResultValue.Value)
下一个
下一个
ListBox1.DataSource=myString
端接头
末级

服务的WSDL已损坏,服务提供商需要修复WSDL。它没有损坏。WSDL是由Siebel自动生成的。这并不意味着它没有或不能被破坏。关键问题是什么是您的客户端代理?它是新的服务客户端还是旧的web引用?只是编辑了文章,以包含有关我正在使用的测试客户端的附加信息。wsLOV名称是由WSDL文件定义的服务引用(使用VS2008的“添加服务引用”对话框)。
Public Class Form1

    Private Sub btnGetLOV_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetLOV.Click

        Dim MyService As New wsLOV.EAILOVPortClient

        Dim MyInput As New wsLOV.EAILOVGetListOfValues_Input
        Dim MyParams(0) As wsLOV.ListQuery
        Dim temp As New wsLOV.ListQuery

        Dim MyResult As New wsLOV.EAILOVGetListOfValues_Output

        temp.Active = "Y"
        temp.Type = "CUT_ACCOUNT_TYPE"
        temp.LanguageCode = "ENU"
        MyParams(0) = temp

        MyInput.ListsQuery = MyParams

        Dim MyRequest As New wsLOV.EAILOVGetListOfValuesRequest(MyInput)
        MyResult = MyService.EAILOVGetListOfValues(MyInput)


    End Sub

End Class
Imports System.ServiceModel.Channels
Imports System.ServiceModel

Public Class Form1

    Private Sub btnGetOrg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetOrgType.Click
        ' This example code queries the Siebel web service using the SOAP protocol for a list of
        ' Account (organization) types stored in a List of Values (LOV). The service request
        ' requires that a SOAP header be added that contains the username, password, and session
        ' type. We have to add this header because the WSDL file definition generated by Siebel
        ' does not include the header definition. The WSDL file was added to the VS2008 project as
        ' a Service Reference named "wsGetLOV"

        ' Create address headers for special services and add them to an array
        Dim addressHeader1 As AddressHeader = AddressHeader.CreateAddressHeader("UsernameToken", "http://siebel.com/webservices", "TESTUSER")
        Dim addressHeader2 As AddressHeader = AddressHeader.CreateAddressHeader("PasswordText", "http://siebel.com/webservices", "TESTPASSWORD")
        Dim addressHeader3 As AddressHeader = AddressHeader.CreateAddressHeader("SessionType", "http://siebel.com/webservices", "None")
        Dim addressHeaders() As AddressHeader = {addressHeader1, addressHeader2, addressHeader3}

        ' Endpoint address constructor with URI and address headers
        ' Replace <servername> in the following line with the name of your Siebel server.
        ' For example: http://actual-server/eai_enu...
        Dim endpointAddressWithHeaders As New EndpointAddress(New Uri("http://<servername>/eai_enu/start.swe?SWEExtSource=WebService&SWEExtCmd=Execute&WSSOAP=1"), addressHeaders)
        Dim MyService As New wsGetLOV.EAILOVPortClient("EAILOVPort", endpointAddressWithHeaders)

        Dim MyInput As New wsGetLOV.EAILOVGetListOfValues_Input
        Dim MyOutput As wsGetLOV.EAILOVGetListOfValues_Output
        Dim MyList(0) As wsGetLOV.ListQuery

        MyList(0) = New wsGetLOV.ListQuery
        MyList(0).Active = "Y"
        MyList(0).LanguageCode = "ENU"
        MyList(0).Type = "CUT_ACCOUNT_TYPE"
        MyInput.ListsQuery = MyList

        MyOutput = MyService.EAILOVGetListOfValues(MyInput)

        Dim myStrings As New List(Of String)

        ' We use nested loops because the results returned by the service is a list of
        ' lists though in our case, the result set is a list with a single item (this item
        ' being a list of multiple items)
        For Each myResultList As wsGetLOV.ListResult In MyOutput.ListsResult
            For Each myResultValue As wsGetLOV.ListValueResult In myResultList.ListValuesResult
                myStrings.Add(myResultValue.Value)
            Next
        Next

        ListBox1.DataSource = myStrings

    End Sub
End Class