我想通过URL访问服务中公开的所有方法.如果假设URL将是:
http://localhost/MyService/MyService.svc
Run Code Online (Sandbox Code Playgroud)
我如何访问方法:
我有一个包含WCF库项目的VS 2010解决方案和另一个使用该Web服务的项目.在VS 2012开放后,它进行了升级.
代理现在将List <T>类型作为数组返回,即使CollectionMappings明确设置为Generic.List.
可能会发生什么?
其他人在这里有类似的问题,但他正在从VS 2012降级到VS 2010.
编辑:我仔细检查,Reference.svcmap包含:
<CollectionMappings>
<CollectionMapping TypeName="System.Collections.Generic.List`1" Category="List" />
</CollectionMappings>
Run Code Online (Sandbox Code Playgroud)
但Reference.cs包含的内容如下:
public xxx.ServiceReference1.ADUser[] get_ADUsers;
Run Code Online (Sandbox Code Playgroud)
在Web服务中它是:
public List<ADUser> get_ADUsers(string wildcard, string sortexp, string sortorder)
Run Code Online (Sandbox Code Playgroud)
更多信息(2012年12月12日添加):
在VS2010中创建的解决方案在另一台PC上运行良好.它从该PC检入TFS.在这个有问题的PC上,我们进行了映射和GET.当我们尝试构建时,我们得到了这个错误,其中服务引用中使用的所有List <T>类型都以某种方式被视为数组.我们在有问题的PC上安装了VS 2010并获得了该解决方案.同样的错误也存在.所以,它似乎与VS 2012无关.
所有PC都是Windows 7 Professional.
更多信息(2012年12月19日添加):
项目打开时,本地PC上的ServiceReferences/ServiceReference1/Reference.cs会自动修改.变化是巨大的.以下是其中的一小部分:

显示了两种方法.List <string> get_Hotlines()成为string [] get_Hotlines()和List <string> get_HotlinesBySite()成为string [] get_HotlinesBySite().
即使没有我的要求,为什么文件也会改变?VS 2012升级日志表示两个文件已更改,但Reference.cs不是其中之一.
希望使客户端通过WCF将序列化的Message对象发送回服务器.
为了让最终开发人员(不同部门)更容易,他们不需要知道如何编辑他们的配置文件来设置客户端端点数据.
也就是说,端点也没有嵌入/硬编码到客户端也很棒.
在我看来,混合方案是推出的最简单的解决方案:
IF(在config中描述)USE配置文件ELSE回退到硬编码端点.
我发现的是:
new Client(); 如果找不到配置文件定义,则会失败new Client(binding,endpoint); 作品因此:
Client client;
try {
client = new Client();
}catch {
//Guess not defined in config file...
//fall back to hard coded solution:
client(binding, endpoint)
}
Run Code Online (Sandbox Code Playgroud)
但有没有办法检查(除了try/catch)以查看配置文件是否有一个端点声明?
如果在配置文件中定义,但上述配置是否也会失败,但配置不正确?区分这两个条件会好吗?
我有一个支持Silverlight的WCF服务的网站.该服务工作正常,我可以浏览到浏览器中的WSDL页面没有问题.
现在,我正在尝试在DLL中创建一个客户端.我需要以编程方式创建整个客户端,因为它是在DLL中调用的,无论出于何种原因(按设计?),它都不会从自己的配置文件中读取ServiceModel部分.
所以这是我的代码:
Dim endp As EndpointAddress = New EndpointAddress("http://www.mydomain.com/licensing/lic.svc")
Dim bind As WSHttpBinding = New WSHttpBinding()
Dim svc = New lnt.licClient(bind, endp)
Dim rsp = svc.CheckIt(key)
Run Code Online (Sandbox Code Playgroud)
但是当我调用svc.CheckIt方法时,我收到以下错误:
Content Type application/soap+xml; charset=utf-8 was not supported by service http://www.mydomain.com/licensing/lic.svc.
The client and service bindings may be mismatched.
{"The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'application/soap+msbin1'.."}
Run Code Online (Sandbox Code Playgroud)
如何正确创建我的客户端,以便这些正确"匹配"?
提前致谢!!!
我需要使用具有Date和Time类型元素的Java Webservice.
来自wsdl的示例:
...
<xsd:element name="fromTime" nillable="true" type="xsd:time" />
<xsd:element name="dateOfInspection" type="xsd:date" />
...
Run Code Online (Sandbox Code Playgroud)
通过添加服务引用消费Web服务时Visual Studio 2008生成以下代码:
[System.Xml.Serialization.SoapElementAttribute(DataType="time", IsNullable=true)]
public System.Nullable<System.DateTime> fromTime { ... }
[System.Xml.Serialization.SoapElementAttribute(DataType="date")]
public System.DateTime dateOfInspection { ... }
Run Code Online (Sandbox Code Playgroud)
使用innerException发送消息会导致反射错误:
'time'是SoapElementAttribute.DataType属性的无效值.只能为基本类型指定该属性.
删除DataType ="time"和DataType ="date"属性时,一切似乎都有效.但修改生成的代码是一种反模式.那么有没有其他方法让这个工作?
更新:
只有日期或时间元素可以为空时才存在问题!
我在微软连接网站上报告了一个错误.如果您遇到同样的问题,可以在这里投票:https: //connect.microsoft.com/VisualStudio/feedback/details/534453/consuming-java-webservice-with-nullable-date-and-time-elements-in -wcf-生成-无效-数据类型的属性
更新2:
微软证实这是一个错误,并且不太理解.
更新3:
我检查VS2010,它仍然生成错误的代码.顺便说一下,我们最终修改了生成的代码......
嗨,我一直在努力解决我的问题,但无法做任何事情.
问题是
http://localhost/productservice/service.svc 在我的浏览器中键入此地址时,它给出了503 Service Unavailable错误
当我从VS 2010运行我的代码时,它给了我
位于http://localhost/ProductsService/Service.svc的HTTP服务太忙了.例外.
ProductService使用ApplicationPoolIdentity在ASP.NET v4.0集成应用程序池中运行.
我不知道自己需要做什么!
(Windows 7 Home&IIS7)
使用basicHttpBinding
服务器端配置是
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="AdventureWorksEntities" connectionString="metadata=res://*/ProductsModel.csdl|res://*/ProductsModel.ssdl|res://*/ProductsModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=PINCHY\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults …Run Code Online (Sandbox Code Playgroud) 我正在测试一个接受DC类型参数的WCF服务方法,我的一些DC属性是List类型.我如何传递值,我在""中尝试过字符串,不接受,请参阅附带的截图.
附带的屏幕截图中的AdjReason是List类型.希望我对我的问题很清楚.
谢谢,阿达什
list datacontract wcftestclient visual-studio-2010 wcf-client
如何在c#中以编程方式使用证书身份验证设置ServiceClient?
我不想使用.config.
using(var srv = GetServiceInstance())
{
srv.DoStuff()
}
private TheServiceClient GetServiceInstance()
{
var service = new TheServiceClient(CreateWsHttpBinding(), CreateEndpointAdress());
return service;
}
private static WSHttpBinding CreateWsHttpBinding()
{
var wsHttpBinding = new WSHttpBinding();
wsHttpBinding.Security.Mode = SecurityMode.Message;
wsHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
wsHttpBinding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
wsHttpBinding.Security.Transport.Realm = "";
wsHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
wsHttpBinding.Security.Message.NegotiateServiceCredential = true;
wsHttpBinding.Security.Message.ClientCredentialType = MessageCredentialType.Certificate;
wsHttpBinding.Name = "Bindingname";
wsHttpBinding.CloseTimeout = TimeSpan.FromMinutes(1);
wsHttpBinding.OpenTimeout = TimeSpan.FromMinutes(1);
wsHttpBinding.ReceiveTimeout = TimeSpan.FromMinutes(10);
wsHttpBinding.SendTimeout = TimeSpan.FromMinutes(1);
wsHttpBinding.BypassProxyOnLocal = false;
wsHttpBinding.TransactionFlow = false;
wsHttpBinding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
wsHttpBinding.MaxBufferPoolSize = 524288; …Run Code Online (Sandbox Code Playgroud) 我有一个使用WCF的VB .NET应用程序.我已经为代码中的所有内容设置了客户端超时:
Dim oMastSrv As MastSvc.IclsIOXferClient = Nothing
Dim binding As New ServiceModel.NetTcpBinding("NetTcpBinding_IclsIOXfer")
Dim intTimeout As Integer = 2500
binding.SendTimeout = New TimeSpan(0, 0, 0, 0, intTimeout)
binding.ReceiveTimeout = New TimeSpan(0, 0, 0, 0, intTimeout)
binding.OpenTimeout = New TimeSpan(0, 0, 0, 0, intTimeout)
binding.CloseTimeout = New TimeSpan(0, 0, 0, 0, intTimeout)
Dim address As New ServiceModel.EndpointAddress("net.tcp://" & GetSrvIP(intSrvID) & ":30000/MyMastSvc")
oMastSrv = New MastSvc.IclsIOXferClient(binding, address)
Try
oMastSrv.ServiceConnect( ... )
oMastSrv.InnerChannel.OperationTimeout = New TimeSpan(0, 0, 0, 0, intTimeout)
Catch ex As …Run Code Online (Sandbox Code Playgroud) 我有两个WCF客户端正在使用第三方Web服务.
这两个客户端执行相同的方法调用.在一种情况下,它每次都有效,另一种情况下,我得到"没有端点监听......"的消息.
据我所知,这两个调用之间的唯一区别是它们位于两个不同的客户端exes中,这意味着.exe.config文件不一样.它们使用相同的源代码,这些代码在Visual Studio中的两个项目之间共享,因此没有区别.
但实际上这两个exe.config文件的内容(几乎)完全相同; 唯一的区别是失败调用的exe.config具有更大的绑定元素的maxBufferSize和maxReceivedMessageSize属性值,以及更大的sendTimeout值.
wcf-client ×10
wcf ×7
c# ×2
wcf-binding ×2
.net ×1
datacontract ×1
iis-7 ×1
list ×1
tfs ×1
tfs2010 ×1
vb.net ×1
wcf-security ×1