标签: wcf-client

如何在运行时通过URL使用WCF Web服务?

我想通过URL访问服务中公开的所有方法.如果假设URL将是:

http://localhost/MyService/MyService.svc
Run Code Online (Sandbox Code Playgroud)

我如何访问方法:

  1. 如果我想有一个ServiceReference
  2. 如果没有服务参考,我该怎么办?

wcf wcf-binding wcf-client

15
推荐指数
2
解决办法
6万
查看次数

WCF代理返回数组而不是列表甚至收集类型== Generic.List

我有一个包含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不是其中之一.

tfs wcf wcf-client tfs2010 visual-studio-2012

12
推荐指数
2
解决办法
5471
查看次数

WCF客户端配置:如何检查端点是否在配置文件中,如果没有则回退到代码?

希望使客户端通过WCF将序列化的Message对象发送回服务器.

为了让最终开发人员(不同部门)更容易,他们不需要知道如何编辑他们的配置文件来设置客户端端点数据.

也就是说,端点也没有嵌入/硬编码到客户端也很棒.

在我看来,混合方案是推出的最简单的解决方案:

IF(在config中描述)USE配置文件ELSE回退到硬编码端点.

我发现的是:

  1. new Client(); 如果找不到配置文件定义,则会失败
  2. 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)以查看配置文件是否有一个端点声明?

如果在配置文件中定义,但上述配置是否也会失败,但配置不正确?区分这两个条件会好吗?

wcf wcf-client wcf-configuration

11
推荐指数
2
解决办法
5037
查看次数

以编程方式创建WCF客户端

我有一个支持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)

如何正确创建我的客户端,以便这些正确"匹配"?
提前致谢!!!

wcf-client type-mismatch

11
推荐指数
1
解决办法
2万
查看次数

在WCF中使用带有日期和时间元素的Java Webservice

我需要使用具有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,它仍然生成错误的代码.顺便说一下,我们最终修改了生成的代码......

c# wcf wcf-client

11
推荐指数
1
解决办法
1958
查看次数

服务不可用503 +位于http://localhost/ProductsService/Service.svc的HTTP服务太忙

嗨,我一直在努力解决我的问题,但无法做任何事情.

问题是

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=&quot;Data Source=PINCHY\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=True;MultipleActiveResultSets=True&quot;" 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)

wcf iis-7 wcf-client http-status-code-503

11
推荐指数
2
解决办法
3万
查看次数

在测试我的WCF服务时如何将值传递给List <string>属性?

我正在测试一个接受DC类型参数的WCF服务方法,我的一些DC属性是List类型.我如何传递值,我在""中尝试过字符串,不接受,请参阅附带的截图.在此输入图像描述

附带的屏幕截图中的AdjReason是List类型.希望我对我的问题很清楚.

谢谢,阿达什

list datacontract wcftestclient visual-studio-2010 wcf-client

11
推荐指数
1
解决办法
6746
查看次数

以编程方式配置WCF服务客户端和证书身份验证

如何在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)

c# wcf wcf-binding wcf-client wcf-security

11
推荐指数
1
解决办法
1万
查看次数

服务中断时,WCF客户端会忽略超时值

我有一个使用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)

.net vb.net wcf wcf-client

11
推荐指数
1
解决办法
3499
查看次数

在<URI>没有可以接受该消息的端点.这通常是由错误的地址或SOAP操作引起的

我有两个WCF客户端正在使用第三方Web服务.

这两个客户端执行相同的方法调用.在一种情况下,它每次都有效,另一种情况下,我得到"没有端点监听......"的消息.

据我所知,这两个调用之间的唯一区别是它们位于两个不同的客户端exes中,这意味着.exe.config文件不一样.它们使用相同的源代码,这些代码在Visual Studio中的两个项目之间共享,因此没有区别.

但实际上这两个exe.config文件的内容(几乎)完全相同; 唯一的区别是失败调用的exe.config具有更大的绑定元素的maxBufferSize和maxReceivedMessageSize属性值,以及更大的sendTimeout值.

wcf-client

10
推荐指数
1
解决办法
2万
查看次数