标签: wcf-client

拦截WCF客户端中的消息

有没有人有Web Service Extensions的经验?我花时间尝试从MS示例中创建Web服务扩展.

我有一个.net 3.5 Web服务客户端,通过添加对WSDL的引用,通过VS IDE"Project> Add Service Reference"构建.这构建了我的Web服务客户端,一切正常.

我需要拦截我的Web服务客户端的请求和响应正文.我发现了许多对Web服务扩展的引用,但是我已经厌倦了攻击,并且无法启动我的扩展.

我在这里使用了MS示例"如何实现SOAP扩展"(http://msdn.microsoft.com/en-us/library/7w06t139.aspx),它为请求/响应流构建了一个记录器.

相关的MS文章"Soap Message Modification"(http://msdn.microsoft.com/en-us/library/esw638yk(VS.85).aspx)展示了如何为Web客户端启用SOAP扩展:

实现SOAP扩展

有两种方法可以在客户端或服务器应用程序上运行SOAP扩展.首先,您可以配置应用程序以运行扩展.要将SOAP扩展配置为针对所有Web服务(尤其是vroot)上的所有Web方法运行,请编辑<soapExtensionTypes>Web.config文件中的" 元素"部分.以下代码显示type属性值必须在一行上,并包含扩展的完全限定名称,以及签名程序集的version,culture和public key标记.

<configuration>
<system.web>
<webServices>
<soapExtensionTypes>
<add type ="Contoso.MySoapExtension,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35"priority ="1"group ="0"/>
</soapExtensionTypes>
</ webServices>
</system.web>
</ configuration>

我已经将traceextension编译到它自己的类库中,并在web服务项目的web.config中引用它,如下所示:

<add type ="TraceExtension,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = ef8757fac167b8d8"priority ="1"group ="High"/>

没有快乐.没有记录任何内容,也没有命中断点.

然后我删除了引用的类,并将源代码放入Web服务项目中.

我尝试添加对它的引用(我的命名空间是ServcieTest001):

<add type ="ServiceTest001.TraceExtension"group ="High"priority ="1"/>

我使用以下线程作为指南,使我能够扩展"获取-wot-soap-data-from-a-web-reference-client-running-in-asp-net"(http://stackoverflow.com/questions/300674/getting-raw-soap-data-from-a-web-reference-client-running-in-asp-net).

仍然没有快乐.然后我从上面的线程中复制了代码,当我发出SOAP请求时仍然无法触发扩展.

任何人都可以指向一个功能可下载的Web服务扩展演示项目,所以我可以反汇编它,找出我错过的东西?

c# wcf soap wcf-client

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

可以在IClientChannel代理上调用Abort()会抛出异常吗?

根据文档和文章,如果遇到意外的异常/错误,建议在客户端代理上调用Abort().请参阅以下(简化):

MyServiceClient proxy = null;
try {
    proxy = new MyServiceClient();
    proxy.DoSomething();
    proxy.Close();
} catch (Exception ex) {
    if (proxy != null)
        proxy.Abort();
}
Run Code Online (Sandbox Code Playgroud)

是否有可能调用Abort()自己抛出异常?对Abort()的调用应该在自己的try/catch中吗?

wcf proxy abort wcf-client

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

通过代理服务器连接到WCF服务时出现奇怪的异常

在以下情况下会发生异常" 相对URI不支持此操作. "

我有一个WCF服务:

[ServiceContract(ProtectionLevel=ProtectionLevel.None)]
public interface IMyService
{
    [OperationContract]
    [FaultContract(typeof(MyFault))]
    List<MyDto> MyOperation(int param);

    // other operations
}

public class MyService : IMyService
{
    public List<MyDto> MyOperation(int param)
    {
        // Do the business stuff and return a list of MyDto
    }

    // other implementations
}
Run Code Online (Sandbox Code Playgroud)

MyFault并且MyDto是两个非常简单的带有[DataContract]属性的类,每个类只有三个[DataMember]类型string, int and int?.

此服务在Win 2008 Server上的IIS 7.0中与ASP.NET应用程序一起托管.我正在使用SVC文件MyService.svc,该文件直接位于网站的根目录中.web.config中的服务配置如下:

<system.serviceModel>
  <services>
    <service name="MyServiceLib.MyService">
      <endpoint address="" binding="wsHttpBinding"
          bindingConfiguration="wsHttpBindingConfig" 
          contract="MyServiceLib.IMyService" />
    </service>
  </services>
  <bindings>
    <wsHttpBinding>
      <binding name="wsHttpBindingConfig"> …
Run Code Online (Sandbox Code Playgroud)

wcf wcf-client

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

.NET Web服务(asmx)超时问题

我正在连接供应商提供的Web ASMX服务并通过网络发送一组数据.当您向项目添加服务引用时,我的第一次尝试达到了默认情况下Visual Studio在app.config文件中引发的1分钟超时.我把它增加到10分钟,另一次超时.1小时,另一个超时:

Error: System.TimeoutException: The request channel timed out while waiting for
a reply after 00:59:59.6874880. Increase the timeout value passed to the call to
 Request or increase the SendTimeout value on the Binding. The time allotted to
this operation may have been a portion of a longer timeout. ---> System.TimeoutE
xception: The HTTP request to 'http://servername/servicename.asmx' has exceeded the allotted timeout of 01:00:00. The time allotted to this
operation may have been a portion of a longer timeout. …
Run Code Online (Sandbox Code Playgroud)

.net wcf web-services timeout wcf-client

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

覆盖Wcf客户端最大连接,防止客户端限制

我有一个客户端进程尝试使用'BasicHttpBinding'向服务器发出多个并发请求.客户端尝试向服务器发出10个或更多并发请求,但服务器日志表明在任何时候最多只有2个并发请求正在进行中,这显然会降低客户端生成的吞吐量.在客户端,似乎有一些限制正在进行.我们由服务提供商提供的配置包含如下行为:

        <basicHttpBinding>
            <binding name="BasicHttpBinding_IService" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="01:00:00"
                allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
                maxBufferSize="2047483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2047483647"
                messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
                useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="1073741823"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <security mode="TransportCredentialOnly">
                    <transport clientCredentialType="Windows" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>
            </binding>
        </basicHttpBinding>
Run Code Online (Sandbox Code Playgroud)

此外,我们在客户端中有以下连接管理条目:

<system.net>
    <connectionManagement>
        <add address="*" maxconnection="10" />
    </connectionManagement>
</system.net>
Run Code Online (Sandbox Code Playgroud)

那么我需要做些什么来防止在客户端上发生限制,以便可以有超过2个最大并发请求到WCF服务,谢谢

throttling wcf-client

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

WCF超时问题?

我有一个长期采用基于WCF的流程.如果有任何帮助,WCF服务在Azure中运行.我相信这个问题与超时有关:

1)Winforms客户端在绑定部分中具有以下.config设置:

 <wsHttpBinding>
  <binding name="XXX" closeTimeout="00:05:00" openTimeout="00:05:00"
   receiveTimeout="00:10:00" sendTimeout="00:10:00" bypassProxyOnLocal="false"
   transactionFlow="false" hostNameComparisonMode="StrongWildcard"
   maxBufferPoolSize="10000000" maxReceivedMessageSize="10000000"
   messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
   allowCookies="false">
   <readerQuotas maxDepth="255" maxStringContentLength="8192" maxArrayLength="16384"
    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
   <reliableSession ordered="true" inactivityTimeout="00:10:00"
    enabled="false" />
   <security mode="TransportWithMessageCredential">
    <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
    <message clientCredentialType="UserName" negotiateServiceCredential="true" algorithmSuite="Default" establishSecurityContext="false"/>
   </security>
  </binding>
 </wsHttpBinding>
Run Code Online (Sandbox Code Playgroud)

2)WCF服务在web.config中具有以下绑定部分

   <wsHttpBinding>
    <binding name="XXX" maxReceivedMessageSize="10000000" sendTimeout="00:10:00" receiveTimeout="00:10:00" closeTimeout="00:10:00" openTimeout="00:10:00">
     <security mode="TransportWithMessageCredential">
      <message clientCredentialType="UserName" establishSecurityContext="false" />
     </security>
     <readerQuotas maxArrayLength="2000000" maxBytesPerRead="10000000" maxStringContentLength="10000000" maxDepth="255" />
    </binding>

   </wsHttpBinding>
Run Code Online (Sandbox Code Playgroud)

3)我在WCF中有一个长时间运行的方法(通常为2分钟).客户端调用该方法,执行时间超过1分钟的客户端将被抛出异常.这是最内在的例外:

  <InnerException>
    <Type>System.Net.Sockets.SocketException</Type>
    <Message>An existing connection was forcibly closed by the …
Run Code Online (Sandbox Code Playgroud)

wcf timeout azure wcf-client

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

如何使用MessageHeader.CreateHeader()方法向WCF邮件头添加属性?

我正在使用以下代码添加WCF自定义标头

 MessageHeader header = MessageHeader.CreateHeader("Key", "ns", "Value");
 OperationContext.Current.OutgoingMessageHeaders.Add(header);
Run Code Online (Sandbox Code Playgroud)

有了这个,我也想补充一下

    xmlns:wsa="http://www.w3.org/2005/08/addressing"
   wsa:IsReferenceParameter="1"
Run Code Online (Sandbox Code Playgroud)

作为此Message标头的属性.

有没有办法将上面的命名空间和属性添加到邮件头?

wcf wcf-client

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

从客户端的不同文件加载WCF配置

许多人面临的WCF中的一个常见问题是不可能从不同的配置文件加载客户端配置.

当开发人员想要部署一些二进制文件以及独立配置文件(也可能位于资源文件或其他配置文件中)时,这是常见的情况,以避免修改主配置文件.

我找到了两个参考文献:

http://weblogs.asp.net/cibrax/archive/2007/10/19/loading-the-wcf-configuration-from-different-files-on-the-client-side.aspx

http://social.msdn.microsoft.com/forums/en-US/wcf/thread/f33e620a-e332-4fd4-ae21-88c750437355/

哪个是关于它的最佳解决方案?

有关最佳解决方案的任何建议吗?我使用VS 2008和.NET 3.5.

c# wcf load configuration-files wcf-client

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

如何使用WCF WebApi的HttpClient发布POCO

我正在通过NuGet(pkg版本0.3.0)使用WCF WebApi堆栈(预览4),似乎无法弄清楚如何使用"POST a POCO" HttpClient.

鉴于以下内容:

Public Class MyInfo
    Public Property MyDate As DateTime
    Public Property MyId As Guid
End Class

...
Dim value = New MyInfo With {.MyDate = Today, .MyId = Guid.NewGuid()}

Using client as New HttpClient(baseUri)
    Using response = client.Post(requestUri, New ObjectContent(Of MyInfo)(value))
        ' Do stuff
    End Using
End Using
...
Run Code Online (Sandbox Code Playgroud)

Post调用该方法时,我得到以下异常:

The 'XmlSerializer' serializer cannot serialize the type 'MyInfo'.

at Microsoft.ApplicationServer.Http.XmlMediaTypeFormatter.GetSerializerForType(Type type)
at Microsoft.ApplicationServer.Http.XmlMediaTypeFormatter.OnWriteToStream(Type type, Object value, Stream stream, HttpContentHeaders contentHeaders, TransportContext context)
at …
Run Code Online (Sandbox Code Playgroud)

wcf wcf-client wcf-web-api

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

WCF在随机调用中获取"在接收到HTTP响应时发生错误"

我从客户端调用SOAP API时,随机接收(并非总是)"接收到HTTP响应出错".它不会每次都发生.我的应用程序本身是一个WCF服务.

客户端配置:

<binding name="AbcBinding" 
                 sendTimeout="00:02:45"
                 closeTimeout="00:02:45"
                 openTimeout="00:02:45"
                 receiveTimeout="00:10:00"
                 bypassProxyOnLocal="false"
                 maxBufferPoolSize="2147483647" 
                 maxReceivedMessageSize="2147483647">
            <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
                <security mode="Transport" >
                <transport clientCredentialType="Basic" />
                </security>
        </binding>

<client>
      <endpoint binding="basicHttpBinding" bindingConfiguration="AbcBinding"
                contract="AbcContract" name="AbcBinding" />
    </client>
Run Code Online (Sandbox Code Playgroud)

码:

var configFactory = new ConfigurationChannelFactory<AbcContract>("AbcBinding"), ConfigFile, "localhost:9198/AbcCall");

            #region Basic http authentication
            if (configFactory.Credentials != null)
            {
                    var defaultCredentials = configFactory.Endpoint.Behaviors.Find<ClientCredentials>();
                    configFactory.Endpoint.Behaviors.Remove(defaultCredentials);

                    var loginCredentials = new ClientCredentials();
                    loginCredentials.UserName.UserName = "UserName";
                    loginCredentials.UserName.Password = "Password";
                    configFactory.Endpoint.Behaviors.Add(loginCredentials);

            }
Run Code Online (Sandbox Code Playgroud)

编辑 在本地环境中,它可以正常工作,具有以下配置:useDefaultWebProxy="false" proxyAddress="http://127.0.0.1:8888"

但在部署服务器上,我遇到以上配置错误: …

wcf wcf-client wcf-configuration .net-4.5.2

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