无法将类型隐式转换为System.Net.Authorization?

时间:2014-02-18 16:57:40

标签: c# asp.net asp.net-4.0

我正在添加.cs(Class)文件并在其中使用Web Reference:

using ServiceMemberIDSS;

当我输入以下代码时,我得到_authHeader的返回值:

private Authorization IDSSCredentials()
{
    ServiceMemberIDSS.AuthorizeHeader _authHeader = new AuthorizeHeader();
    _authHeader.UserName = "theUserName";
    _authHeader.Password = "thePassword";
    return _authHeader;
}

返回的最后一个_authHeader标记用红色加下划线,当我将鼠标悬停在它上面时这样说:

Cannot implicitly convert type 'ServiceMemberIDSS.AuthorizeHeader' to 'System.Net.Authorization'

如何解决这个问题?我需要在服务响应之前将用户名和密码发送给服务。

AuthorizeHeader在Members.wsdl文件夹中的App_WebReferences文件中定义为XML,如下所示:

<s:element name="AuthorizeHeader" type="tns:AuthorizeHeader" />
  <s:complexType name="AuthorizeHeader">
    <s:sequence>
      <s:element minOccurs="0" maxOccurs="1" name="UserName" type="s:string" />
      <s:element minOccurs="0" maxOccurs="1" name="Password" type="s:string" />
    </s:sequence>
    <s:anyAttribute />
  </s:complexType>

1 个答案:

答案 0 :(得分:0)

只需使用命名空间限定返回类型和new()。像这样。

private ServiceMemberIDSS.AuthorizeHeader IDSSCredentials()

    ServiceMemberIDSS.AuthorizeHeader _authHeader = new ServiceMemberIDSS.AuthorizeHeader();

    _authHeader.UserName = "theUserName";
    _authHeader.Password = "thePassword";
    return _authHeader;
}