我是使用API和WCF的新手,所以如果我遗漏任何信息,请告诉我。
我似乎无法解决这个问题。我有两个针对此特定脚本的服务引用以及我为第一个引用传递的调用没有错误,但是,当我第一次尝试从第二个引用调用某些内容时,API会抛出MessageSecurityError,具体来说:
未处理的类型' System.ServiceModel.Security.MessageSecurityException'发生在mscorlib.dll
附加信息:HTTP请求未经授权使用客户端身份验证方案' Basic'。从服务器收到的身份验证标题是“基本领域”。
//Creating SalesOrder Client
private static SoCalls.SalesOrderServiceClient CreateSalesOrderServiceClient()
{
BasicHttpBinding myBinding = new BasicHttpBinding();
myBinding.MaxReceivedMessageSize = 65536 * 2;
myBinding.Security.Mode = BasicHttpSecurityMode.Transport;
myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
EndpointAddress ea = new EndpointAddress("address1");
SoCalls.SalesOrderServiceClient client = new SoCalls.SalesOrderServiceClient();
client.ClientCredentials.UserName.UserName = "username";
client.ClientCredentials.UserName.Password = "password";
return client;
}
//Create OrderEntry Client
private static DocCalls.SalesOrderServiceClient CreateDataWriteServiceResponse()
{
BasicHttpBinding myBinding = new BasicHttpBinding();
myBinding.MaxReceivedMessageSize = 65536 * 2;
myBinding.Security.Mode = BasicHttpSecurityMode.Transport;
myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
EndpointAddress ea = new EndpointAddress("address2");
DocCalls.SalesOrderServiceClient client = new DocCalls.SalesOrderServiceClient();
client.ClientCredentials.UserName.UserName = "username";
client.ClientCredentials.UserName.Password = "password";
return client;
}
这是我的配置文件:
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_ISalesOrderService">
<security mode="Transport" >
<transport clientCredentialType="Basic" />
</security>
</binding>
<binding name="BasicHttpBinding_ISalesOrderService1">
<security mode="Transport" >
<transport clientCredentialType="Basic" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="address1"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_ISalesOrderService"
contract="SoCalls.ISalesOrderService"
name="BasicHttpBinding_ISalesOrderService" />
<endpoint address="address2"
binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_ISalesOrderService1"
contract="DocCalls.ISalesOrderService"
name="BasicHttpBinding_ISalesOrderService1" />
</client>
有人能指出我的错误或指出我可以找到如何进展的方向吗?
答案 0 :(得分:0)
我意识到这个错误来自于我的第二次初始化中的错误凭据:
CreateDataWriteServticeRepsonse()
虽然用户名和密码看起来与第一次初始化相同
CreateSalesOrderServiceClient()
我只是将第一个用户名和密码复制+粘贴到我的第二次初始化中,并且必须有一个我没看到的空格或某种类型的标记。