【发布时间】:2016-07-03 11:38:01
【问题描述】:
我正在使用 c#,而且我是新手。 我有一个网络服务的 URL:http://grillassessmentservice.cloudapp.net/GrillMenuService.svc
登录:jobs@isolutions.ch
密码:cleancode
这给了我 XML:
<service xmlns="http://www.w3.org/2007/app" xmlns:atom="http://www.w3.org/2005/Atom"xml:base="http://grillassessmentservice.cloudapp.net/GrillMenuService.svc/">
<workspace>
<atom:title>Default</atom:title>
<collection href="GrillMenus">
<atom:title>GrillMenus</atom:title>
</collection>
<collection href="GrillMenuItemQuantities">
<atom:title>GrillMenuItemQuantities</atom:title>
</collection>
<collection href="GrillMenuItems">
<atom:title>GrillMenuItems</atom:title>
</collection>
</workspace>
</service>
我的控制台应用程序中有该 c# 代码:
static void Main(string[] args)
{
Uri serviceUri = new Uri("http://grillassessmentservice.cloudapp.net/GrillMenuService.svc");
var serviceCreds = new NetworkCredential("foobar@outlook.com", "test");
var cache = new CredentialCache();
cache.Add(serviceUri, "Basic", serviceCreds);
var service = new GrillMenu.GrillMenuContext(serviceUri)
{
Credentials = cache
};
foreach (var grillMenu in service.GrillMenus.Expand(g => g.GrillMenuItemQuantity))
{
Console.WriteLine("Menu: {0}", grillMenu.Name);
foreach (var grillMenuItemQuantity in grillMenu.GrillMenuItemQuantity)
{
service.LoadProperty(grillMenuItemQuantity, "GrillMenuItem");
Console.WriteLine("{0} x {1}", grillMenuItemQuantity.Quantity,
grillMenuItemQuantity.GrillMenuItem.Name);
}
Console.WriteLine();
}
}
但我无法访问网络服务。有人可以解释一下它是如何工作的吗? 我试图通过添加参考来访问,在登录名和密码上给我错误。在那个阶段: 谢谢。
【问题讨论】:
标签: c# xml web-services