【发布时间】:2014-04-29 14:19:10
【问题描述】:
我正在尝试调用需要一些身份验证的 Web 服务,尽管我对如何传递此身份验证的凭据有点困惑。 Web 服务提供者提供的示例 SOAP 请求如下:
<s:Envelopexmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:ManagedUserHeaderxmlns:h="http://www.url.com/web/services/"xmlns="http://www.axumtech.com/web/services/"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<RegistrationKey>12345678910</RegistrationKey>
<CompanyName>TEST</CompanyName>
</h:ManagedUserHeader>
</s:Header>
<s:Bodyxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<GetContinentsxmlns="http://www.url.com/web/services/" />
</s:Body>
</s:Envelope>
我将在 C# 中使用 .Net 使用 Web 服务。我之前做过一些简单的 Web 服务请求,但只有在请求中传入一个简单字符串作为检索响应的一部分。我知道要让这个请求生效,我必须传入一个包含两个属性、一个注册密钥和一个公司名称的 ManagedUserHeader 对象,尽管每当我尝试以这种方式对其进行编程时,我得到的只是过载错误。
到目前为止,这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Umbraco.Core;
using Umbraco.Core.Services;
using website.AxumStaticData;
namespace website.umbraco
{
public partial class StaticDataService : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
StaticDataWebServiceSoapClient service = null;
bool success = false;
var guid = "12345678910";
var companyName = "Test";
var compressionSoapHeader = new AxumStaticData.CompressionSoapHeader();
var managedUserHeader = new AxumStaticData.ManagedUserHeader();
managedUserHeader.CompanyName = companyName;
managedUserHeader.RegistrationKey = new Guid(guid);
try{
service = new StaticDataWebServiceSoapClient();
var result = service.GetContinents(compressionSoapHeader,managedUserHeader);
}finally{
if (!success && service != null){
service.Abort();
}
}
}
}
}
根据我在 Visual Studio 中收到的错误,这行有一些无效参数:
var result = service.GetContinents(compressionSoapHeader,managedUserHeader);
但是,如果我删除参数,我会收到以下错误:
No overload for method 'GetContinents' takes 0 arguments
我真的为此苦苦挣扎,因为我以前只在纯 XML 中调用过 Web 服务,因此我们将不胜感激。如果需要,我很乐意提供更多信息。
【问题讨论】:
-
GetContinents() 中需要什么?
-
@sr28 根据 Visual Studio 需要两个参数,虽然我知道第一个是可选的: ContinentData[]StaticDataWebServiceSoapClient.GetContinents(ref CompressionSoapHeader CompressionSoapHeader, ref ManagedUserHeader ManagedUserHeader)
标签: c# .net web-services service-reference