我与webservice建立了连接,现在我得到了一个不同的web服务(https而不是http),代码不再起作用了。有谁知道我必须改变它才能使用https?
public AppWebService_PortClient openConn()
{
BasicHttpBinding binding = new BasicHttpBinding { };
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
EndpointAddress epa = new EndpointAddress("https://172.16.restOfURL");
AppWebService_PortClient ws = new AppWebService_PortClient(binding, epa);
ws.ClientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential("theUser", "ThePassword", "TheDomain");
return ws;
}
这给我提供了以下错误:
System.ServiceModel.dll中出现'System.Configuration.ConfigurationErrorsException'类型的第一次机会异常
其他信息:类型'Microsoft.VisualStudio.Diagnostics.ServiceModelSink.Behavior,
如果我按下继续,它最终会更进一步告诉我
System.ServiceModel.dll中出现'System.ArgumentException'类型的第一次机会异常
其他信息:提供的URI方案“https”无效;预计'http'。
这是与网络服务交谈的代码,
public async Task getData()
{
if (IsRunning)
return;
try
{
IsRunning = true;
Groups = new ObservableCollection<ProductGroup>();
var ws = referance.openConn();
Item itemSimple = new Item();
GetItems wsrequest = new GetItems(itemSimple, "", "", "0");
GetItems_Result result = await ws.GetItemsAsync(wsrequest);
ItemCategory ic = new ItemCategory();
GetItemCategory catrequest = new GetItemCategory(ic);
GetItemCategory_Result catresult = await ws.GetItemCategoryAsync(catrequest);
var results = catresult.itemCategoryExport.ItemCategorys;
foreach (ItemCategorys itemc in results)
{
ProductGroup p = new ProductGroup(itemc.Code, itemc.Description, "/Assets/logo.jpg");
Groups.Add(p);
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
IsRunning = false;
}