标签: wcf-client

WCF测试客户端错误:无法调用服务

尝试将WCF测试客户端与我的WCF服务一起使用时出错.这是服务代码:

[ServiceContract]
public interface IEmployeeService
{
    [OperationContract(Name = "GetEmployee")]
    [WebGet(RequestFormat = WebMessageFormat.Xml,
        UriTemplate = "/Employees/{employeeNumber}")]
    Employee GetEmployee(string employeeNumber);
}

public Employee GetEmployee(string employeeNumber)
{
    var employeeNumberValue = Convert.ToInt32(employeeNumber);
    var employee = DataProvider.GetEmployee(employeeNumberValue);
    return employee;
}

<system.serviceModel>
    <services>
        <service name="Employees.Services.EmployeeService"
                 behaviorConfiguration="metaBehavior">
            <endpoint address=""
                      behaviorConfiguration="webHttp"
                      binding="webHttpBinding"
                      contract="Employees.Services.IEmployeeService">
            </endpoint>
            <endpoint address="mex"
                      binding="mexHttpBinding"
                      contract="IMetadataExchange">
            </endpoint>
        </service>
    </services>
    <behaviors>
        <endpointBehaviors>
            <behavior name="webHttp">
                <webHttp/>
            </behavior>
        </endpointBehaviors>
        <serviceBehaviors>
            <behavior name="metaBehavior">
                <serviceMetadata httpGetEnabled="true" />
            </behavior>
        </serviceBehaviors>
    </behaviors>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

我能够使用WCF测试客户端连接到服务,但是当我尝试调用GetEmployee(employeeNumber)时,我收到以下错误:

无法调用该服务.可能的原因:服务离线或无法访问; 客户端配置与代理不匹配; 现有代理无效.有关更多详细信息,请参阅堆栈跟踪.您可以尝试通过启动新代理,还原到默认配置或刷新服务来进行恢复.

我能够通过从浏览器发送请求成功调用此服务.

知道为什么我不能使用WCF测试客户端吗?

rest wcf wcf-client

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

使用Wcf流式传输图像文件

我想通过Wcf将大图像发送到服务器.我可以将其作为字节[]传递.我该怎么做.什么是MTOM ...我在哪里可以找到样本......?

streaming wcf wcf-client

5
推荐指数
1
解决办法
3761
查看次数

在WCF调用类中捕获失败连接的位置?

我正在尝试编写一个封装WCF调用的类(客户端是Silverlight,如果重要的话).这一切都在游泳,但我不知道如何陷阱连接失败,好像服务器不会响应.似乎在ChannelFactory生成的代码中某处发生了一些工作,但我不确定.也欢迎一般代码审查.:)

围绕创建通道的底线,或try/catch中的begin或async结果委托不会捕获失败的连接.我想让那个catch运行ServiceCallError事件.

public class ServiceCaller : IDisposable
{
    private IFeedService _channel;

    public ServiceCaller()
    {
        var elements = new List<BindingElement>();
        elements.Add(new BinaryMessageEncodingBindingElement());
        elements.Add(new HttpTransportBindingElement());
        var binding = new CustomBinding(elements);
        var endpointAddress = new EndpointAddress(App.GetRootUrl() + "Feed.svc");
        _channel = new ChannelFactory<IFeedService>(binding, endpointAddress).CreateChannel();
    }

    public void MakeCall(DateTime lastTime, Dictionary<string, string> context)
    {
        AsyncCallback asyncCallBack = delegate(IAsyncResult result)
        {
            var items = ((IFeedService)result.AsyncState).EndGet(result);
            if (ItemsRetrieved != null)
                ItemsRetrieved(this, new ServiceCallerEventArgs(items));
        };
        _channel.BeginGet(lastTime, context, asyncCallBack, _channel);
    }

    public event ItemsRetrievedEventHandler ItemsRetrieved;
    public event ServiceCallErrorHandler ServiceCallError; …
Run Code Online (Sandbox Code Playgroud)

wcf wcf-client

5
推荐指数
1
解决办法
7886
查看次数

.NET Web服务客户端:呼叫失败后自动重试

我们有一个.NET客户端使用SSL调用Java Web服务。有时,由于连通性差而导致呼叫失败(.NET客户端是从最奇怪的位置使用的UI)。我们希望实现一种自动重试机制,该机制将在放弃之前自动重试失败的呼叫X次。仅应使用特定类型的连接异常(而不是由Web服务本身生成的异常)来完成此操作。

我们试图在绑定/通道级别上找到方法,但是失败了...有什么想法吗?

谢谢,yonadav

.net wcf web-services wcf-client

5
推荐指数
1
解决办法
2024
查看次数

从WCF服务转换类型

我相信这一定是一个非常普遍的问题.我有两个WCF服务,基本上暴露了对一个大型服务的标准访问和管理员访问.

Foo每种服务都有类似的方法.Foo采用TemplateInfo我的服务中定义的类型的参数.

在我的客户端,我有一个ClientAdminClient.Client.Foo(TemplateInfo)期待的Client.TemplateInfo同时AdminClient.Foo(TemplateInfo)期待AdminClient.TemplateInfo.我知道一旦达成服务Client.TemplateInfo并且AdminClient.TemplateInfo是相同的事情.

我试图弄清楚如何实例化TemplateInfo和/或将其转换为使用客户端和管理方法.有相当数量的代码来创建这个对象,所以我希望不要为每种类型复制它.

类型在共享程序集中定义,我在代理中"重用类型".但我得到两种不同的类型,因为我有两个服务引用.

像(AdminClient)TemplateInfo这样做会很棒,但也许我会创建一个克隆方法来转换类型.

c# wcf type-conversion wcf-client

5
推荐指数
1
解决办法
2468
查看次数

使用 WCF 将服务器的传输和消息签名证书作为客户端分离

我目前正在将 WCF 客户端集成到 Java Web 服务中。服务器要求客户端使用 SSL 和要签名的消息通过证书进行身份验证。

我已成功通过 SSL、Signed 等将消息发送到服务器。但是,服务器响应消息也已签名,但使用的证书与用于验证服务器的证书不同。

WCF 客户端不喜欢这种行为。它失败并显示以下消息:“传入的消息使用的令牌与用于加密正文的令牌不同。这是意料之外的。” 这里详细描述这个问题。

在 Google 上环顾四周,我发现通过实现 ClientCredentials 和其他安全相关类并添加新扩展,可以将客户端传输证书与唱歌证书分离。您可以在此处阅读有关它的所有详细信息。但是,我在弄清楚我必须在何处扩展才能在客户端模式下为服务器证书提供相同的行为时遇到了一些麻烦。

任何有关该主题或参考的帮助将不胜感激。

提前致谢。

wcf wcf-binding wcf-client wcf-security

5
推荐指数
1
解决办法
1571
查看次数

从WCF客户端消耗非wcf SOAP错误(定义了soap fault)

我有一个非Wcf服务器,我从WCF客户端调用,我需要访问已注册的soap故障,如果服务器抛出它(它包含我需要用户的反馈).我使用了如何从WCF客户端访问SOAP 1.1故障详细信息中的示例(没有错误契约),但是给定了一个痛苦我已经在wsdl中定义了故障契约,至少每个SOAP规范,并且错误包含错误代码和错误字符串.

<wsdl:types>
    <schema elementFormDefault="qualified" targetNamespace="http://www.cisco.com/BTS10200/i01" xmlns="http://www.w3.org/2001/XMLSchema">
        ...
        <complexType name="BtsSoapException">
            <sequence>
                <element name="error_code" type="xsd:int"/>
                <element name="error_string" nillable="true" type="xsd:string"/>
            </sequence>
        </complexType>
        <element name="fault" type="impl:BtsSoapException"/>
...

<wsdl:message name="BtsSoapException">
    <wsdl:part element="impl:fault" name="fault"/>
</wsdl:message>
...

<wsdl:portType name="Bts10200Operations">
    <wsdl:operation name="login">
        <wsdl:input message="impl:loginRequest" name="loginRequest"/>
        <wsdl:output message="impl:loginResponse" name="loginResponse"/>
        <wsdl:fault message="impl:BtsSoapException" name="BtsSoapException"/>
    </wsdl:operation>
...
Run Code Online (Sandbox Code Playgroud)

服务导入可以正确识别所有这些并生成正确的代码构造:

[System.Runtime.Serialization.DataContractAttribute(Name="BtsSoapException", Namespace="http://www.cisco.com/BTS10200/i01")]
[System.SerializableAttribute()]
public partial class BtsSoapException : object ...

....

[System.ServiceModel.ServiceContractAttribute(Namespace="http://www.cisco.com/BTS10200/i01", ConfigurationName="CiscoBTSService.Bts10200Operations")]
public interface Bts10200Operations {
    [System.ServiceModel.OperationContractAttribute(Action="", ReplyAction="*")]
    [System.ServiceModel.FaultContractAttribute(typeof(TestCiscoBTS.CiscoBTSService.BtsSoapException), Action="", Name="fault")]
    TestCiscoBTS.CiscoBTSService.loginResponse login(TestCiscoBTS.CiscoBTSService.loginRequest request);
...
Run Code Online (Sandbox Code Playgroud)

当我login()使用无效帐户调用时,我会根据wsdl获得正确的响应: …

c# wcf soap wcf-client

5
推荐指数
1
解决办法
3902
查看次数

当URI尚未知道时,在容器中注册WcfClient

在我注册新的WCF端点时,我不知道URI是什么......

public void Install(IWindsorContainer container, IConfigurationStore store)
{
   var defaultClientModel = new DefaultClientModel
   {
     Endpoint = WcfEndpoint
       .ForContract<IMyService>()
       .BoundTo(new WSHttpBinding(SecurityMode.None))
       .At(  URI??? )
   };

   container.Register(WcfClient.ForChannels(defaultClientModel));
}
Run Code Online (Sandbox Code Playgroud)

有没有什么方法可以在请求IMyService实例时从容器中检索URI(这是在知道的时候)?

是否有工厂方法/动态参数可以使用的东西?

castle-windsor wcf-client

5
推荐指数
1
解决办法
592
查看次数

将应用程序配置嵌入到WCF中的C#代码中

我有一个客户端程序连接到我的wcf服务。我想将应用程序配置嵌入C#代码中,直到用户无法更改甚至看不到app.config为止。

但是我不能将这两个配置设置带到C#代码中:

<system.diagnostics>
    <sources>
      <source propagateActivity="true" name="System.ServiceModel" switchValue="Warning">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          </add>
          <add name="NewListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging" switchValue="Warning,ActivityTracing" >
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          </add>
          <add name="NewListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add initializeData="Trace.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
          name="NewListener" traceOutputOptions="LogicalOperationStack, DateTime, Timestamp, ProcessId, ThreadId, Callstack">
        <filter type="" />
      </add>
    </sharedListeners>
  </system.diagnostics>
Run Code Online (Sandbox Code Playgroud)

<system.net>
    <defaultProxy enabled="true" useDefaultCredentials="true" >
      <proxy autoDetect="True" …
Run Code Online (Sandbox Code Playgroud)

c# configuration wcf wcf-client wcf-configuration

5
推荐指数
1
解决办法
2259
查看次数

使用 WCF 客户端库从 Asp.net core 使用 WCF 服务 (nettcp)

我们有一个以 nettcp 模式托管的 WCF 服务和 WCF 客户端库,服务和客户端都是使用 .net 框架创建的。

现在我们正在使用 Asp.net core 2.1 创建新应用程序,但我们仍然需要使用相同的旧 WCF 客户端库来使用上面创建的 WCF 服务。

将此 WCFClient 库引用(.net 框架)添加到我们的 Asp.net 核心应用程序中。这里使用下面的代理构造函数来传递我的端点详细信息。

public LoggingServiceProxy(Binding binding, EndpointAddress remoteAddress)
            : base(binding, remoteAddress)

new LoggingServiceProxy(new EndpointAddress("net.tcp://localhost:9100/LoggingService/Tcp"), new NetTcpBinding(SecurityMode.None));
Run Code Online (Sandbox Code Playgroud)

添加 System.ServiceModel.NetTcp 和 System.ServiceModel.Primitives NUGET 引用后,解决了所有其他错误。但是代码线程在执行代理代码时突然中止

((ICommunicationObject)this.channel).Open();
Run Code Online (Sandbox Code Playgroud)

此后没有更多信息,调试消息可用。没有引发异常。所以我们不知道它是什么?

注意:当我停止服务进行测试时,我清楚地收到异常“EndPointNotFound”。

预期的行为是能够使用 Asp.net Core 应用程序 -> WCF 客户端库(.net 框架) -> WCF 服务 nettcp(.net 框架)中的服务

在对自动生成的代理代码进行了更多研究后,发现此问题发生在 InnerChannel_Opened() 和 InnerChannel_Closed() 事件中。上面的事件得到了以下代码行“lock (this.channelLock)”,这导致了问题。没有提出异常。只是线程中止/退出。当注释掉这些事件时,它工作正常,但我不太确定注释这些自动生成的代码是否可以。

               lock (this.channelLock)
                {
                    if (this.IsDisposed)
                    {
                        throw new InvalidOperationException("Cannot use disposed object.");
                    }

                    if (this.Opened …
Run Code Online (Sandbox Code Playgroud)

.net c# wcf-client asp.net-core

5
推荐指数
0
解决办法
816
查看次数