标签: wcf-client

WCF - > ASMX和Cookies

我有一个通过WCF客户端与WCF服务通信的Web应用程序.在调用我的代码时,已经发出了身份验证cookie,并且我依赖于期望这些身份验证cookie的ASMX服务.

我需要将cookie从Web应用程序通过WCF客户端传递到WCF服务到ASMX服务.

有任何想法吗?看起来我最好的选择可能是将allowCookies设置为false,解析出cookie头,尝试在WCF服务上重新创建它们,然后将它们附加到SOAP请求中.

注意:我查看了这篇文章,这篇文章似乎很接近但不太适用于这个问题.在链接方案中,ASMX服务正在创建cookie,该cookie必须由同一WCF客户端持久保存到后续ASMX服务.

wcf wcf-client

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

为长时间运行的WCF应用程序选择正确的连接属性

我正在使用WCF在C#中编写客户端/服务器应用程序.我的所有测试都没问题,但是一旦我部署了服务,我发现与服务器通信时出现了随机问题.我启用了调试并在服务器中看到了这样的消息:

The communication object, System.ServiceModel.Channels.ServerReliableDuplexSessionChannel, cannot be used for communication because it has been Aborted.
Run Code Online (Sandbox Code Playgroud)

模式是这样的:

  • 客户端正在发送查询
  • 服务正在处理查询
  • 服务正在发回一些东西
  • 活动边界处于"停止"水平 - 一切似乎都很好
  • 将可靠会话的inactivetivityTimeout添加到上次联系的日期时间,并且您具有服务抛出的异常的时间戳

应用程序如下所示:服务实例提供了与数据库交互的API方法,其类型为"netTcpBinding".几个客户端(大约40个)连接并从服务中随机调用方法.即使没有发送或接收任何东西,客户也可以保持开放几天.

以下是相关位:

服务:

    [ServiceContract(CallbackContract = typeof(ISVCCallback), SessionMode = SessionMode.Required)]
    [ExceptionMarshallingBehavior]
...
Run Code Online (Sandbox Code Playgroud)

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext=true)]
    public class SVCService : ISVC
...
Run Code Online (Sandbox Code Playgroud)

服务配置:

    <behaviors>
      <serviceBehaviors>
        <behavior name="behaviorConfig">
          <serviceMetadata httpGetEnabled="false" httpGetUrl="" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceThrottling maxConcurrentCalls="50" maxConcurrentSessions="1000"
            maxConcurrentInstances="50" />
        </behavior>
      </serviceBehaviors>
    </behaviors>

    <bindings>
      <netTcpBinding>
        <binding name="tcpBinding" closeTimeout="00:01:00" openTimeout="00:10:00"
          receiveTimeout="23:59:59" sendTimeout="00:01:30" transferMode="Buffered"
          listenBacklog="1000" …
Run Code Online (Sandbox Code Playgroud)

wcf wcf-binding wcf-client

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

指定要与WCF客户端一起使用的传出IP地址

如何在调用WCF服务时定义WCF客户端使用的LocalEndPoint(如果客户端计算机有多个IP地址)?

我有一台位于DMZ中的机器有两个IP地址,外部IP地址可以通过防火墙通过我们位于外部服务提供商的网络服务器的VPN连接到达.在此计算机上运行基于WCF和Unity的自定义应用程序服务器,该服务器应充当代理或应用程序级网关(ALG).它应接受来自Web服务器的服务调用,并使用wcf客户端工厂重新生成服务调用,将它们转发到LAN中的真实应用服务器.

当使用wcf客户端工厂在此代理上重新创建服务调用时,wcf客户端应使用此计算机的第二个内部IP地址,因为只允许来自此内部IP地址的消息通过防火墙才能到达局域网中的应用服务器.不幸的是,我们的wcf客户端代理始终选择使用第一个"外部"IP地址创建传出消息.我正在寻找一种方法来明确设置wcf客户端代理使用的IP地址.

我只能找到一个允许定义LocalEndPoint或ClientBaseAddress的WCF绑定元素:CompositeDuplexBindingElement.据我所知,这个属性是告诉服务器在哪里发送asynch回复消息,所以它与我正在寻找的设置不同.

任何想法我能做些什么才能找到可行的解决方案?

提前感谢任何有用的建议!!

这似乎是一个类似的问题,只使用TcpClient/Sockets而不是WCF: 在C#中指定用于TCPClient/Socket的传出IP地址

另一个,这次是关于SoapClient: 在发送传出请求之前将新的SoapClient绑定到特定的IP地址

wcf ip-address wcf-binding wcf-client

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

尝试使用SVCUTIL.EXE创建Web服务代理时出现"未生成代码"错误

当尝试使用SVCUTIL.EXE(在命令行或通过Visual Studio)创建Web服务代理(WCF )时,我得到以下无意义的错误消息.

注意:该服务没有任何问题,因为它可以在另一台机器上正常工作.这是Windows的新安装,该服务在我的本地盒子上.使用不同机器上的URL在我的机器上生成相同的代理工作正常.

这是怎么回事?!

Microsoft (R) Service Model Metadata Tool
[Microsoft (R) Windows (R) Communication Foundation, Version 4.0.30319.1]
Copyright (c) Microsoft Corporation.  All rights reserved.

Attempting to download metadata from 'https://ws1.example.com/ShoppingCartWS/WCF/ShoppingCartWCF.svc?wsdl' using WS-Metadata Exchan
Error: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageCont
Error: Schema with target namespace '' could not be found.
XPath to Error Source: //wsdl:definitions[@targetNamespace='']/wsdl:portType[@name='IShoppingCart']


Error: Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType …
Run Code Online (Sandbox Code Playgroud)

wcf wcf-client

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

当Transfermode = Stream时,将文件名和长度参数添加到WCF流

与讨论该主题的所有SO帖子相比,我对在a中包装流对象不感兴趣[MessageContract],因为在模式(afaik)中不允许这样做.

当我处于流模式时,如何向客户端返回一些元数据,例如长度和文件名?我可以添加WCF/SOAP标头吗?我该怎么做?

我正在寻找扩展文件流类并添加一个[MessageHeader]属性,但我无法让它工作.

.net streaming wcf filestream wcf-client

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

WCF,生成的DataMember List <>代理类属性是否为空?

我正在使用DataContractDataMember属性装饰WCF中的一个简单对象.我有一个List<T>属性,并故意设计它在第一次访问时实例化支持字段(如果为null).该类的缩写版本如下.

[DataContract]
public class FieldSetData 
{
    private List<FormFieldData> _formFields;

    [DataMember]
    public List<FormFieldData> FormFields
    {
        get
        {
            if (this._formFields == null)
            {
                this._formFields = new List<FormFieldData>();
            }
            return this._formFields;
        }
        set
        {
            this._formFields = value;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

问题是,在生成的客户端/代理类上,我无法在第一次手动实例化时访问该属性,因为它是null(这是if上面的逻辑应该处理的).

下面的第二行代码返回null:

//proxy class version
FieldSetData data = new FieldSetData();
data.FormFields.Add(new FormFieldData());  //FormFields property is null
Run Code Online (Sandbox Code Playgroud)

我必须这样做:

//instantiate the List<T> property
FieldSetData data = new FieldSetData { FormFields = new List<FormFieldData>() };
data.FormFields.Add(new FormFieldData());
Run Code Online (Sandbox Code Playgroud)

我对WCF很新,所以也许我在这里遗漏了一些东西?我认为代理类生成会尊重属性中的 …

c# asp.net wcf properties wcf-client

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

如何使用配置在WCF客户端上设置用户名/密码?

我知道我可以通过代码使用来做到这一点

myClient.ClientCredentials.UserName.UserName = "User";
myClient.ClientCredentials.UserName.Password = "Password";
Run Code Online (Sandbox Code Playgroud)

是否可以通过配置为客户端提供相同的功能?

.net c# wcf ws-security wcf-client

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

使用.Net4 WCF路由器服务进行动态路由

我正在寻找使用.net 4 wcf服务进行动态路由的示例.请帮我.

wcf-routing wcf-binding wcf-client

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

可以为多个WCF服务合同添加一个服务引用

我在一个WCF库中定义了多个服务契约,这些托管在Windows服务下托管.这些服务在Windows服务配置文件中公开如下:

<services>
  <service behaviorConfiguration="ReportingComponentLibrary.TemplateServiceBehavior"
    name="ReportingComponentLibrary.TemplateService">
    <endpoint address="" binding="wsHttpBinding" contract="ReportingComponentLibrary.ITemplateService" bindingConfiguration="wsHttp" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" ></endpoint>
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8080/ReportingComponentLibrary/TemplateService/" />
      </baseAddresses>
    </host>
  </service>
  <service behaviorConfiguration="ReportingComponentLibrary.TemplateServiceBehavior"
    name="ReportingComponentLibrary.TemplateReportService">
    <endpoint address="" binding="wsHttpBinding" contract="ReportingComponentLibrary.ITemplateReportService" bindingConfiguration="wsHttp" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" ></endpoint>
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8080/ReportingComponentLibrary/TemplateReportService/" />
      </baseAddresses>
    </host>
  </service>
</services>
Run Code Online (Sandbox Code Playgroud)

现在,当我在客户端应用程序中添加服务引用时,

是否可以为上述两个服务添加一个服务引用或

我需要为每个服务/服务合同分开参考.

更新:

以下是我的申请详情:

我有三个不同的项目:

  1. WCF服务库
  2. 用于托管WCF服务的Windows服务
  3. 客户端 - 测试控制台应用程序

现在,WCF服务库中的App.Config如下:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>     

  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="wsHttp" maxReceivedMessageSize="50000000" maxBufferPoolSize="50000000" messageEncoding="Mtom">
          <readerQuotas maxDepth="500" maxStringContentLength="500000000" maxArrayLength="500000000"
          maxBytesPerRead="500000000" maxNameTableCharCount="500000000" />
        </binding> …
Run Code Online (Sandbox Code Playgroud)

wcf wcf-client

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

WCF System.Object序列化

我有一个要求,我必须使用System.Object作为WCF中的参数.因为它不可序列化,所以我收到消息,因为它不支持操作,因为它使用System.Object.解决这个问题的任何方法.

.net c# wcf wcf-client

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

如何以编程方式在托管服务上设置服务主体名称

要使用配置文件执行上述操作,我会这样做:

<endpoint
  address="...."
  binding="netTcpBinding"
  bindingConfiguration="MyBinding"
  contract="IService1">
  <identity>
    <servicePrincipalName value="name"/>
  </identity>
</endpoint>
Run Code Online (Sandbox Code Playgroud)

但是如何将其添加到下面的代码中?

Uri uri = new Uri("http://example.com/service");
ServiceHost host = new ServiceHost(typeof(Service1), uri);

NetTcpBinding binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.Message;
binding.Security.Message.ClientCredentialType = MessageCredentialType.Windows;
host.AddServiceEndpoint(typeof(IService1), binding, uri);
host.Open();
Run Code Online (Sandbox Code Playgroud)

.net c# wcf wcf-client wcf-configuration

0
推荐指数
1
解决办法
3884
查看次数

WCF客户端和非wcf客户端

您能告诉我WCF客户端和非WCF客户端之间有什么区别吗?

当我使用生成SvcUtil工具WCF服务的代理,并把在客户端,是什么创造 - WCF客户端或者非WCF客户端?

我应该何时使用WCF客户端和非WCF客户端?

wcf wcf-client

0
推荐指数
1
解决办法
1414
查看次数