在wcf Web服务中调用SAP ME Web服务

时间:2016-03-05 20:40:15

标签: c# asp.net web-services wcf soap

我有一个soap web服务(sap me web service),我生成了wcf代理。没问题,我开发的WinForms应用程序没问题 现在我尝试在我的wcf服务中使用它(域网络中的webHttpBinding绑定)但我有一个身份验证错误: WCF - HTTP请求未经授权使用客户端身份验证方案' Basic'。从服务器收到的身份验证标头是' Basic realm =" mySoapServiceName" 这是IIS用户问题吗?

由于

2 个答案:

答案 0 :(得分:1)

SAP正在使用基本身份验证。您需要在创建代理后指定用户名和密码,例如:

proxy.Credentials.UserName.UserName = "joe";
proxy.Credentials.UserName.Password = "doe";

答案 1 :(得分:0)

BasicHttpBinding myBinding = new BasicHttpBinding();

myBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;

myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;
EndpointAddress ea = new EndpointAddress("url de mon web service soap");

SfcServices.SFCProcessingInClient myClient = new SfcServices.SFCProcessingInClient(myBinding, ea);

myClient.ClientCredentials.UserName.UserName = _MESwsLogin;
myClient.ClientCredentials.UserName.Password = _MESwsPassword;

SfcServices.SFCStateRequestMessage_sync srm = new SfcServices.SFCStateRequestMessage_sync();
SfcServices.SFCStateRequest sr = new SfcServices.SFCStateRequest();
srm.SfcStateRequest = sr;
sr.SiteRef = new SfcServices.SiteRef();
sr.SiteRef.Site = _MESsite;
sr.SfcRef = new SfcServices.SFCRef();
sr.SfcRef.Sfc = "12345678903";

sr.includeSFCStepList = true;

SfcServices.SFCStateConfirmationMessage_sync response = myClient.FindStateByBasicData(srm);
strOrdreFab = response.SfcStateResponse.SFCStatus.Sfc.ShopOrderRef.ShopOrder;
strCodeProduit = response.SfcStateResponse.SFCStatus.Sfc.ItemRef.Item;
strIndice = response.SfcStateResponse.SFCStatus.Sfc.ItemRef.Revision;