标签: wcf-client

WCF客户端 - 为WS-Security时间戳签名指定签名算法

我有一个WCF客户端正在向非WCF服务发送消息,并且该服务在处理用于签署WS-Security Timestamp元素的HMAC-SHA1签名方法时遇到问题.理想情况下,我们想使用RSA-SHA1签名方法,但我无法让WCF使用该签名方法.

我正在使用的绑定是一个自定义绑定,它允许我通过HTTPS发送SAML 2.0令牌:

<customBinding>
    <!-- This binding is a WS2007FederationHttpBinding without Secure Sessions that uses Text message encoding. -->
    <binding
        name="WS2007FederationHttpBinding_NoSecureSession_Text"
        closeTimeout="00:01:00"
        openTimeout="00:01:00"
        receiveTimeout="00:10:00"
        sendTimeout="00:01:00">
        <security
            authenticationMode="IssuedTokenOverTransport"
            requireSignatureConfirmation="true"
            securityHeaderLayout="Lax"
            messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10"
            keyEntropyMode="CombinedEntropy"
            includeTimestamp="true">
            <issuedTokenParameters
                tokenType="urn:oasis:names:tc:SAML:2.0:assertion">
                <!-- This describes the STS. That is, the URL, the binding to use, and its Identity -->
                <issuer
                    address="http://hostname//STS.svc"
                    binding="ws2007HttpBinding"
                    bindingConfiguration="StsUserNameBindingConfiguration">
                    <identity>
                        <!-- This is the certificate used for signing on the STS. -->
                        <!-- Replace "sts-signing-certificate-thumbprint" with the actual thumbprint of the STS's signing …
Run Code Online (Sandbox Code Playgroud)

c# wcf ws-security wcf-client xml-signature

9
推荐指数
1
解决办法
5494
查看次数

WCF客户端错误处理

我正在消耗一个笨重的WCF服务器,偶尔会抛出各种异常,并且还会返回一些错误string.我根本无法访问服务器代码.

我想覆盖内部WCF客户端请求调用方法并处理服务器返回的所有内部异常和硬编码错误,并在Fault发生错误时引发事件,伪:

class MyClient : MyServiceSoapClient
{
    protected override OnInvoke()
    {
        object result;
        try
        {
            result = base.OnInvoke();
            if(result == "Error")
            {
                //raise fault event
            }
        catch
        {
            //raise fault event
        }
    }        
}
Run Code Online (Sandbox Code Playgroud)

因此,当我打电话时myClient.GetHelloWorld(),它通过我的重写方法.

怎么能实现这一目标?
我知道我不必使用生成的客户端,但我不想再次重新实现所有的合同,我想使用生成的ClientBase子类或至少它的通道.
我需要的是控制内部请求调用方法.

更新

我读了这个答案,看起来它部分是我正在寻找的,但我想知道是否有办法只附加一个IErrorHandler消费者(客户端)代码,我想以ClientBase<TChannel>某种方式将它添加到实例.

更新

这篇文章看起来很有希望,但它不起作用.应用的属性似乎没有生效.我找不到添加IServiceBehavior到客户端的方法.

更新

我试图安装一个IErrorHandler通过IEndpointBehavior.ApplyClientBehavior调用:

public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
{
  clientRuntime.CallbackDispatchRuntime.ChannelDispatcher.ErrorHandlers
           .Add(new ErrorHandler());
}
Run Code Online (Sandbox Code Playgroud)

(clientRuntime是一个参数),但仍会直接跳过异常跳转MyErrorHandler …

c# wcf wcf-client

9
推荐指数
2
解决办法
2904
查看次数

使用svcutil生成WebService代理的问题

在我们的应用程序中,我们被迫使用多个WebServices.在开始时,我们只使用"添加服务引用"菜单选项,以便创建WCF代理.

该向导不生成DataContract,而是生成XML-Serializable类.到目前为止,这么糟糕,但这不是杀手.但是,后来我们注意到,我们丢失了数据,因为生成的代理在归因时添加了Order属性,这导致了问题.

现在我们尝试使用SVCUTIL.EXE从WSDL生成代理类,但我们总是得到以下错误消息:

    C:\temp\WSDL>svcutil /serializer:DataContractSerializer ReadSddsAddressOut.wsdl
Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 3.0.4506.2152]
Copyright (c) Microsoft Corporation.  All rights reserved.

Warning: Das optionale WSDL-Erweiterungselement "body" aus Namespace "http://schemas.xmlsoap.org/wsdl/soap/" wurde nicht behandelt.
XPath: //wsdl:definitions[@targetNamespace='http://post.ch/sdds/address']/wsdl:binding[@name='ReadSddsAddressOutBinding']/wsdl:operation[@name='GeoSuchKanton']/wsdl:input


Warning: Das optionale WSDL-Erweiterungselement "body" aus Namespace "http://schemas.xmlsoap.org/wsdl/soap/" wurde nicht behandelt.
XPath: //wsdl:definitions[@targetNamespace='http://post.ch/sdds/address']/wsdl:binding[@name='ReadSddsAddressOutBinding']/wsdl:operation[@name='GeoSuchKanton']/wsdl:output


Warning: Das optionale WSDL-Erweiterungselement "body" aus Namespace "http://schemas.xmlsoap.org/wsdl/soap/" wurde nicht behandelt.
XPath: //wsdl:definitions[@targetNamespace='http://post.ch/sdds/address']/wsdl:binding[@name='ReadSddsAddressOutBinding']/wsdl:operation[@name='GeoSuchPlz']/wsdl:input


Warning: Das optionale WSDL-Erweiterungselement "body" aus Namespace "http://schemas.xmlsoap.org/wsdl/soap/" wurde nicht behandelt.
XPath: //wsdl:definitions[@targetNamespace='http://post.ch/sdds/address']/wsdl:binding[@name='ReadSddsAddressOutBinding']/wsdl:operation[@name='GeoSuchPlz']/wsdl:output


Warning: …
Run Code Online (Sandbox Code Playgroud)

wsdl wcf-client svcutil.exe

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

如何为WCF客户端指定备用配置文件?

我正在开发一个大型系统,我必须使用WCF来访问Web服务.我的测试代码工作正常,现在我需要将我的WCF客户端代码集成到更大的系统中.我无法添加到现有的"app.config"文件中,并且希望指定一个单独的.config文件供我的客户端代码使用.

我怎样才能做到最好?

谢谢!

wcf configuration-files wcf-client

8
推荐指数
2
解决办法
8088
查看次数

WCF服务客户端生命周期

我有一个WPF应用程序,它使用WCF服务来调用服务器.

我在我的代码中使用此属性来访问该服务

private static IProjectWcfService ProjectService
{
    get
    {
        _projectServiceFactory = new ProjectWcfServiceFactory();
        return _projectServiceFactory.Create();
    }
}
Run Code Online (Sandbox Code Playgroud)

工厂上的Create看起来像这样

    public IProjectWcfService Create()
    {
        _serviceClient = new ProjectWcfServiceClient();

        //ToDo: Need some way of saving username and password 
        _serviceClient.ClientCredentials.UserName.UserName = "MyUsername";
        _serviceClient.ClientCredentials.UserName.Password = "MyPassword";

        return _serviceClient;
    }
Run Code Online (Sandbox Code Playgroud)

要访问服务方法,我使用类似下面的内容.

ProjectService.Save(dto);
Run Code Online (Sandbox Code Playgroud)

对于我想要做的事情,这是一个很好的方法吗?我得到了一个我无法追踪的错误,我认为可能会打开太多的服务客户端连接(这可能吗?)注意我从不关闭服务客户端或重用它.

对于WPF呼叫,WCF服务客户端的最佳做法是什么?

提前致谢...

wcf wcf-client

8
推荐指数
1
解决办法
3684
查看次数

如何从Silverlight应用程序以编程方式设置maxItemsInObjectGraph属性?

我有一个使用WCF服务与数据库通信的Silverlight 3.0应用程序,当我从服务方法返回大量数据时,我得到Service Not Found错误.我相信它的解决方案是简单地更新maxItemsInObjectGraph属性,但我以编程方式创建服务客户端,无法找到设置此属性的位置.这就是我现在正在做的事情:

BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None)
{
    MaxReceivedMessageSize = int.MaxValue,                  
    MaxBufferSize = int.MaxValue
};                        

MyService.MyServiceServiceClient client = new MyService.MyServiceProxyServiceClient(binding, new EndpointAddress(new Uri(Application.Current.Host.Source, "../MyService.svc")));
Run Code Online (Sandbox Code Playgroud)

wcf wcf-client silverlight-3.0 .net-3.5

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

如何设置每次运行服务时WCF测试客户端都将运行

我有一个WCF项目,当我运行它时,它有时会在WCF测试中吃午餐,有时却没有.

如何设置WCF测试客户端始终显示?

wcf wcf-client visual-studio

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

如何实现像WCF一样的Asp.net MVC OneWay/FireAndForget调用呢?

在WCF中你有这样的东西

[ServiceContract]
public interface IDoAuditService
{
    [OperationContract(IsOneWay = true)]
    [WebInvoke]
    void Audit(AuditEntry auditEntry);
}
Run Code Online (Sandbox Code Playgroud)

因此,这将允许消费者发出请求并继续流程而无需等待响应.

我已经尝试使用AsyncController进行Asp.net MVC,但消费者仍然会阻塞并等待,直到在控制器中调用回调.

我想要的是使用Asp.Net MVC但行为WCF喜欢,我想发出请求并继续流程而不等待处理请求

asp.net asp.net-mvc wcf wcf-client

8
推荐指数
1
解决办法
668
查看次数

ChannelFactory可以成为Faulted吗?

假设我正在缓存ChannelFactory<T>并使用它来创建频道.这些通道用于对其他服务进行WCF调用,然后(安全地)处理.

我是否需要担心缓存ChannelFactory出现故障并因此无法创建新频道的情况?如果是的话,我是否需要用新的替换它ChannelFactory

对于ChannelFactory出现故障的情况,我还要感谢一个可重现的具体例子.

c# wcf wcf-client channelfactory

8
推荐指数
1
解决办法
1077
查看次数

带有动态参数的ChannelFactory错误

此问题与动态语言运行时中的Bug以及IIS 7.5相关

ChannelFactory 如果我提供正确类型的动态对象,则挂起.

dynamic src = "MSFT";

var binding = new BasicHttpBinding();
var endpoint = new EndpointAddress("http://www.restfulwebservices.net/wcf/StockQuoteService.svc");
var channel = new ChannelFactory<IStockQuoteService>(binding, endpoint).CreateChannel();

// this will print just fine
Console.WriteLine(channel.GetStockQuote(src as string));

// this will print just fine
Console.WriteLine(new StockQuoteServiceClient().GetStockQuote(src));

// this will never print and the application will hang with no exceptions
Console.WriteLine(channel.GetStockQuote(src));
Run Code Online (Sandbox Code Playgroud)
  • 上面的服务是公共的,不是我的,如果您只是将服务引用添加到代码中提供的端点,您可以自己测试此代码;
  • StockQuoteServiceClient 是由Add Service Reference菜单项创建的,并且使动态对象很好;
  • 当我在Debug上使用F5启动应用程序时,这种神奇不会发生,所有行打印并且程序正确退出;
  • 如果我运行它然后在执行期间附加调试器,我可以看到它挂在调用上channel.GetStockQuote(src);
  • 如果我离开它,程序会占用我所有的记忆;
  • 它只会在我使用自己ChannelFactory的动态对象时挂起,如注释中所述.

ChannelFactory当添加服务引用创建的那个运行得很好时,为什么我将动态对象作为参数挂起?

.net wcf wcf-client channelfactory c#-4.0

8
推荐指数
1
解决办法
323
查看次数