标签: wcfserviceclient

将WCF服务引用添加到多个项目

几个非常基本的问题.我是WCF的新手,我正在构建一个应用程序,它有一个服务项目,一个Web应用程序项目和一些我用于业务逻辑的类库项目等.

我在我的IIS上本地托管WCF并尝试向项目添加服务引用.

问题1.在添加引用时,是否应该单独为每个项目添加服务引用,还是可以在项目中共享相同的Service引用?

我问的原因是因为如果我添加单独的引用,每个引用都会获得它自己的命名空间,当我必须在项目之间传递相同的对象时,我得到一个InvalidCastException,因为每个ServiceClient都有一个不同的命名空间.

示例 - Site.Business.XDataService.XDataServiceClient().GetItem()与Site.Web.XDataService.XDataServiceClient()不同.GetItem()

问题2.我在实现Service接口的类中指定了本地服务的地址,如下所示 -

[ServiceBehavior(Namespace ="http:// localhost:801/XDataService.svc",IncludeExceptionDetailInFaults = true)]

这似乎不对.如果我将我的代码移动到另一个/ live环境,我显然必须再次更改此部分并重新编译.我在哪里可以指定(Web.Config?),以便我可以更改此地址而无需重建我的应用程序?

欣赏任何形式的洞察力.谢谢!

c# wcf wcfserviceclient

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

WCF在代码中动态设置Endpoint和Binding

是的,我已经阅读了有关SO,MSDN和其他网站的其他问题,但我发现没有我能理解的答案.我需要设置我的Silverlight应用程序的WCF引用相对于它加载的站点,但我无法让它工作.服务本身没有问题,它正在运行.当我从本地移动到我的真实服务器时,我的SL应用程序中出现错误,抱怨没有连接到localhost.

这是我的ServiceReferences.ClientConfig档案:

    <configuration>
        <system.serviceModel>
            <bindings>
                <customBinding>
                    <binding name="CustomBinding_AccountManager">
                        <binaryMessageEncoding />
                        <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
                    </binding>
                    <binding name="CustomBinding_FileManager">
                        <binaryMessageEncoding />
                        <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
                    </binding>
                    <binding name="CustomBinding_SiteManager">
                        <binaryMessageEncoding />
                        <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
                    </binding>
                </customBinding>
            </bindings>
            <client>
                <endpoint address="http://localhost:60322/AccountManager.svc"
                    binding="customBinding" bindingConfiguration="CustomBinding_AccountManager"
                    contract="AccountManager.AccountManager" name="CustomBinding_AccountManager" />
                <endpoint address="http://localhost:60322/FileManager.svc" binding="customBinding"
                    bindingConfiguration="CustomBinding_FileManager" contract="FileManager.FileManager"
                    name="CustomBinding_FileManager" />
                <endpoint address="http://localhost:60322/SiteManager.svc" binding="customBinding"
                    bindingConfiguration="CustomBinding_SiteManager" contract="SiteManager.SiteManager"
                    name="CustomBinding_SiteManager" />
            </client>
        </system.serviceModel>
    </configuration>
Run Code Online (Sandbox Code Playgroud)

是的,我优化缓冲区/消息大小,我知道可能的DoS漏洞,暂时忘记它,我需要它们进行大文件传输.我尝试的方法是在实例化客户端时,我使用了这段代码:

    fileManager = new FileManagerClient(new BasicHttpBinding(), new EndpointAddress("http://" + Settings.Host + "/FileManager.svc"));
    accManager = …
Run Code Online (Sandbox Code Playgroud)

wcf web-services webservice-client wcfserviceclient silverlight-4.0

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

WCF:无法调用自己的WCF服务

我有我的WCF服务,我已经从MSTest项目创建了它的引用.以下是我如何调用服务方法的示例:

IEnrollmentService serviceClient = ChannelFactory<IEnrollmentService>
    .CreateChannel(new BasicHttpBinding(),
                   new EndpointAddress("http://localhost/EnrollmentService.svc"));

PublishResult res = serviceClient.PublishEnrollmentProfile(...);
Run Code Online (Sandbox Code Playgroud)

而不是执行我有以下错误:

内容类型application/xml; 响应消息的charset = utf-8与绑定的内容类型不匹配(text/xml; charset = utf-8).如果使用自定义编码器,请确保正确实现IsContentTypeSupported方法.响应的前710个字节是:__CODE__由于EndpointDispatcher上的ContractFilter不匹配,无法在接收方处理"带有Action的消息".这可能是由于合同不匹配(发送方与接收方之间的操作不匹配)或发送方与接收方之间的绑定/安全性不匹配.检查发件人和收件人是否具有相同的合同和相同的绑定(包括安全要求,例如消息,传输,无).---> System.Net.WebException:远程服务器返回错误:(500)内部服务器错误..

据我所知,ContractFilter和EndpointDispatcher之间存在一些问题.我曾试图改善,但发现没什么可以理解的......

我也试过用另一种方式调用wcf服务方法:

EnrollmentServiceClient serviceClient = new EnrollmentServiceClient("http://localhost/EnrollmentService.svc");

PublishResult res = serviceClient.PublishEnrollmentProfile(...);
Run Code Online (Sandbox Code Playgroud)

这又回来了另一个错误:

找不到名为" http://localhost/McActivation/EnrollmentService.svc "的端点元素,并在ServiceModel客户端配置部分中收缩"EnrollmentServiceReference.IEnrollmentService".这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此名称匹配的端点元素.

问题1:

什么是实例化wcf服务客户端的正确方法?

Questions2:

我的情况有什么问题?

非常感谢.

PS有些问题我可以使用WcfTestClient连接到服务,更多细节在这里: WCF服务:不能通过'WebHttpBinding'端点调用方法

PPS这是服务器端WCF服务配置:

<system.serviceModel>
<services>
  <service name="McActivationApp.EnrollmentService" behaviorConfiguration="McActivationApp.EnrollmentServicBehavior">
    <endpoint address="" binding="webHttpBinding" contract="McActivationApp.IEnrollmentService"/>
    <endpoint address="mex" binding="mexHttpBinding" contract="McActivationApp.IEnrollmentService" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="McActivationApp.EnrollmentServicBehavior">
      <serviceMetadata httpGetEnabled="True"/>
      <serviceDebug includeExceptionDetailInFaults="False" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

.net wcf wcfserviceclient

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

WcfSVCHost遇到严重错误,必须退出.这可能是由配置文件无效引起的

System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.Assembly.GetTypes()
   at Microsoft.Tools.SvcHost.ServiceHostHelper.LoadServiceAssembly(String svcAssemblyPath)
Run Code Online (Sandbox Code Playgroud)

我如何循环通过LoaderExceptions属性来查看发生了什么错误,因为它没有命中任何服务并在运行任何代码之前给我这个错误?

谢谢

wcf typeloadexception wcfserviceclient

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

从Service调用方法时,WCF客户端冻结

我有一个奇怪的问题,我的客户端在从我的WCF服务调用方法时会挂起.现在真正奇怪的是,当客户端是控制台应用程序时,这不会发生.当客户端是WinForm或WPF应用程序时,它确实发生.

我创建了一个客户端库,WCF客户端可以使用它连接到服务,如下所示:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;  //needed for WCF communication

namespace DCC_Client
{
    public class DCCClient
    {
        private DuplexChannelFactory<ServiceReference1.IDCCService> dualFactory;

        public ServiceReference1.IDCCService Proxy;

        public DCCClient()
        {
            //Setup the duplex channel to the service...
            NetNamedPipeBinding binding = new NetNamedPipeBinding();
            dualFactory = new DuplexChannelFactory<ServiceReference1.IDCCService>(new Callbacks(), binding, new EndpointAddress("net.pipe://localhost/DCCService"));
        }

        public void Open()
        {
            Proxy = dualFactory.CreateChannel();
        }

        public void Close()
        {
            dualFactory.Close();
        }
    }

    public class Callbacks : ServiceReference1.IDCCServiceCallback
    {
        void ServiceReference1.IDCCServiceCallback.OnCallback(string id, string message, Guid …
Run Code Online (Sandbox Code Playgroud)

wcf wcf-client wcfserviceclient

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

使用 https 的 WCF 服务自托管

当前,在我们的一台客户端机器中,有一个作为 Windows 服务托管的 Wcf 服务,实际上目前这是正常的 http 调用。由于我们需要使用 https 而不是 http,为此我们修改了 app.config 但在启动服务后 https url 不起作用。然后我们尝试使用 URL 保留netsh http add urlacl url=https://+:18732/Peripheral/ user=Everyone。然后我们再次重新启动服务,它无法访问 https url .

我们在 URl 浏览器中收到错误 • 确保启用了 TLS 和 SSL 协议。

这与任何证书问题有关吗?如果是这样,我们如何才能解决这个问题?

web.config 提供如下:-

<system.serviceModel>
<standardEndpoints />
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
  <bindings>
    <basicHttpBinding>
    <binding name ="soapBinding">
    <security mode="Transport">
    <transport clientCredentialType="None"/>
    </security>
    </binding>
    </basicHttpBinding>
    <webHttpBinding>
 <binding name="Bind1" crossDomainScriptAccessEnabled="true">
<security mode="Transport">
 <transport clientCredentialType="None"/>
</security>
</binding>
</webHttpBinding>  
    </bindings>
    <services>
      <service name="Peripheral.Server.Impl.PeripheralServiceImpl" behaviorConfiguration="SvcBhvr">
<host>
<baseAddresses>
  <add baseAddress="https://localhost:18732/Peripheral/" />
  </baseAddresses>
</host>
<endpoint …
Run Code Online (Sandbox Code Playgroud)

ssl wcf windows-services client-certificates wcfserviceclient

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