标签: wcf-client

如何从WCF服务返回接口?

可以说我有一些接口:

public interface IFoo {
  IBar DoesStuff();
}
public interface IBar {
  string Thingo { get; }
}
Run Code Online (Sandbox Code Playgroud)

我在整个代码库中使用此代码.需要将IFoo进程移动到不同的系统上(x64与x32的差异),这是我们使用WFC的原因.我的WCF服务实现了此接口.当我创建"服务引用"时,会创建代理存根,但会更改接口.

public interface IFoo {
   object DoesStuff();
}   
Run Code Online (Sandbox Code Playgroud)

我尝试将IBar/Bar定义为DataService和DataContract,没有区别.有没有办法使用我的界面生成代理代码?

我在想,如果模拟对象可以生成我的界面对象进行测试,那么我是否应该能够获得服务来尊重它?或者做了一些愚蠢和错误的事情?

wcf wcf-client

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

WCF:无法在ServiceModel客户端配置部分中找到引用合同"IService"的默认端点元素.在IIS中托管时

我有一个WCF服务,它在IIS中托管.我也有一个WCF客户端(一个控制台应用程序).我已经习惯于svcutil构建代理类和配置文件,然后将它们添加到我的客户端项目中.它建立得很好.但是当我试图运行该程序时,它抛出了以下异常

无法在ServiceModel客户端配置部分中找到引用合同"IService"的默认端点元素.这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素.

//我的客户端程序代码

namespace MyFirstWCFClient
{
 class Program
 {
    static void Main(string[] args)
    {
        ServiceClient objClient = new ServiceClient();
        Console.WriteLine("Client calling the service....");

        string strName=Console.ReadLine();
        Console.WriteLine(objClient.HelloWorld("Shyju"));
        Console.Read();

    }
 }
}
Run Code Online (Sandbox Code Playgroud)

我的客户端的Output.config文件是

  <?xml version="1.0" encoding="utf-8"?>
   <configuration>
    <system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="WSHttpBinding_IService" closeTimeout="00:01:00"
                openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
                bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
                maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
                messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
                allowCookies="false">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                    maxBytesPerRead="4096" maxNameTableCharCount="16384" />
                <reliableSession ordered="true" inactivityTimeout="00:10:00"
                    enabled="false" />
                <security mode="Message">
                    <transport clientCredentialType="Windows" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="Windows" negotiateServiceCredential="true"
                        algorithmSuite="Default" establishSecurityContext="true" /> …
Run Code Online (Sandbox Code Playgroud)

iis wcf wcf-client

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

WCF代理使用Post即使指定了WebGet属性(仅在从另一个WCF服务调用时) - 导致405错误

我有一个Restful WCF服务坐在另一台配置了WebGet属性的服务器上,以响应HTTP Get方法.我知道该服务正常工作,因为我可以直接通过浏览器调用该服务,并手动执行Get with Fiddler并收到正确的响应.

我在本地计算机上有一个Asp.NET项目,它使用以下代码调用此服务:

代理接口'IProductService':

using System.ServiceModel;
using System.ServiceModel.Web;

namespace Hugo.Infrastructure.Services.Products
{
    [ServiceContract]
    [XmlSerializerFormat]
    public interface IProductService
    {
        [OperationContract(Name = "GetProductById")]
        [WebGet(UriTemplate = "Products/Titles/{id}",
            ResponseFormat = WebMessageFormat.Xml,
            RequestFormat = WebMessageFormat.Xml,
            BodyStyle = WebMessageBodyStyle.Bare)]
        TitleDto GetTitleById(string id);
    }
}
Run Code Online (Sandbox Code Playgroud)

实施'ProductService':

using System.ServiceModel;

namespace Hugo.Infrastructure.Services.Products
{
    public class ProductService : ClientBase<IProductService>, IProductService
    {
        public TitleDto GetTitleById(string id)
        {
            return Channel.GetTitleById(id);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

相关的Web.config部分:

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true">
        <baseAddressPrefixFilters>
        </baseAddressPrefixFilters>      
    </serviceHostingEnvironment>
    ...
    <client>
        <endpoint address="http://server/directory/product.svc" bindingConfiguration="ProductServiceBinding" binding="webHttpBinding" behaviorConfiguration="productService" contract="Project.Infrastructure.Services.Products.IProductService" name="ProductServiceRest" /> …
Run Code Online (Sandbox Code Playgroud)

rest wcf wcf-client

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

如何设置.NET客户端Web服务ClientRuntime.MaxFaultSize

我正在调用一个java webservice,它返回一个包含错误列表的FaultException类型.因此响应消息大小总是很大.

在我的c#(clr3.5)客户端中,我收到以下错误

"已超出传入邮件的最大邮件大小限额(65536).要增加配额,请在相应的绑定元素上使用MaxReceivedMessageSize属性."

我相信解决这个问题的方法是设置ClientRuntime.MaxFaultSize msdn-doc

有没有办法在app.config中执行此操作?

c# wcf wcf-client

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

如何使您的服务参考代理URL动态化?

我有一个Web服务的Web引用:

using (var client = new GetTemplateParamSoapClient("GetTemplateParamSoap"))
{
    TemplateParamsKeyValue[] responsArray = client.GetTemplatesParamsPerId(
        CtId, tempalteIds.ToArray());

    foreach (var pair in responsArray)
    {
        string value = FetchTemplateValue(pair.Key, pair.Value);
        TemplateComponentsData.Add(pair.Key, value);
    }
}
Run Code Online (Sandbox Code Playgroud)

试图从c#代码更改Web引用URL:作为建议:

1)http://www.codeproject.com/KB/XML/wsdldynamicurl.aspx

2)如何使用可配置的URL调用Web服务

3)http://aspalliance.com/283_Setting_Web_Service_References_Dynamically

但是当我尝试做的时候,我发现符号丢失了:

client.Url
Run Code Online (Sandbox Code Playgroud)

另外我找不到"Url_behavior"的属性

c# wcf wcf-client

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

在另一个进程中处理WCF事件

我有一个不可序列化的对象,我想从一个单独的进程访问.我环顾四周,似乎唯一可行的选择是使用WCF,但我不知道如何做到这一点,因为我是WCF的新手.如果我创建一个WCF服务,如何将WinForm"挂钩"到WCF服务中的各种事件中?例如,用户直接与WCF服务通信,我希望WinForm客户端得到通知.我怎么能知道用户何时使用WCF服务做了什么并让WinForm客户端接受了这个?

c# wcf process wcf-client winforms

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

无法访问已处置的对象 - wcf客户端

我有一个WCF客户端,我遇到了问题.
我不时会遇到这个例外:Cannot access a disposed object.这就是我打开连接的方式:

private static LeverateCrmServiceClient crm = null;

public static CrmServiceClient Get(string crmCertificateName)
        {

            if (crm != null)
            {
                crm.Close();
            }
            try 
            {
                crm = new LeverateCrmServiceClient("CrmServiceEndpoint");
                crm.ClientCredentials.ClientCertificate.SetCertificate(
                               StoreLocation.LocalMachine,
                               StoreName.My,
                               X509FindType.FindBySubjectName,
                               crmCertificateName);
            }
            catch (Exception e) 
            {
                log.Error("Cannot access CRM ", e);
                throw;
            }
            return crm;
        }
Run Code Online (Sandbox Code Playgroud)

如您所见,我每次都关闭并重新打开连接.您认为可能是什么问题?

堆:

System.ServiceModel.Security.MessageSecurityException: Message security verification failed. ---> System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.ServiceModel.Security.SymmetricSecurityProtocol'.
  at System.ServiceModel.Channels.CommunicationObject.ThrowIfClosedOrNotOpen()
  at System.ServiceModel.Security.MessageSecurityProtocol.VerifyIncomingMessage(Message& message, TimeSpan timeout, SecurityProtocolCorrelationState[] correlationStates)
  --- …
Run Code Online (Sandbox Code Playgroud)

c# wcf-client objectdisposedexception

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

Windows服务托管TCP WCF服务

我试图在Windows 2008 R2服务器上托管WCF服务作为Windows服务.我按照msdn(在这里找到)提供的指示.只要所有内容都是Visual Studio中同一解决方案的一部分,一切都可以正常工作.但是,我尝试在不同的解决方案(在同一台机器上)创建客户端,但无法找到该服务.我收到如下所示的"添加服务引用错误".

在此输入图像描述

我的目标是能够远程访问wcf服务,但我似乎甚至无法在本地访问它,除非客户端是在同一客户端内创建的.是否有任何指南,教程或有用的提示,任何人都可以让我让这个工作?

更新: 似乎即使Windows服务正在运行,WCF服务似乎也没有监听任何端口.这表明它没有运行.这也解释了为什么每个人都认为我没有运行该服务.我曾经假设,因为Windows服务正在运行并且同一个解决方案客户端工作,所以WCF服务也正常运行.事实证明,每当我运行相同的解决方案客户端时,Visual Studio就会启动WCF服务.

那么,为什么Windows服务不启动WCF服务呢?有任何想法吗?

c# wcf windows-services wcf-client

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

找不到WCF服务引用命名空间

我在我的解决方案中有一个本地WCF服务,我引用了它.但是我的控制器类无法获取Service命名空间?传统上我会使用svcUtil来编写一个包装类但是因为这是内部的我虽然我可以简单地添加"服务引用",然后点击命名空间然后简单地调用我的服务(即var service = new QServiceReference.MyClass();)

我无法显示图片,所以这里是我解决方案的结构,

Solution  
-> Services Folder
    -> QService Folder
       QService Project  
-> Web Folder
    -> Zipporah.Queuing.Web (project)
       -> Services References
          -> QServiceReference
       -> Controllers Folder
          -> KioskProcessController
Run Code Online (Sandbox Code Playgroud)

我的类(KioskProcessController)如下:

using System.Web.Mvc;

using Zipporah.Queuing.Web.QServiceReference; (ITS THIS NAMESPACE REFERENCE THAT DOES NOT WORK)

namespace Zipporah.Queuing.Web.Controllers
{
    public class KioskProcessController : ZipController
    {
        public ActionResult Index()
        {
            return View();
        }

        public ViewResult Queue()
        {
            return View();
        }

        public ViewResult PreAppointment()
        {
            return View();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

对不起,如果那个结构不清楚(如上所述我不能发布图片)

任何线索或想法都会受到最高的赞赏?

c# wcf namespaces wcf-client service-reference

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

由于内部错误,服务器无法处理请求.在WCF错误

我使用C#在框架4.0中编写了我的服务.这是一个返回值的简单方法

Web.config是这样的:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
    <machineKey validationKey="0E1F430D6FFFA91FBEDAEC1D2DDAAC2127EB055DBAFB78328C5BDE83249A94EA66400453B" decryptionKey="A13EACEAAABBECF2D06619924A8" validation="SHA1" decryption="AES" />
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="DecryptCookie.Service1">
        <host>
          <baseAddresses>
            <add baseAddress = "http://localhost:8732/Design_Time_Addresses/WCFandEFService/ProductService/" />
          </baseAddresses>
        </host>
        <endpoint address=""  binding="wsHttpBinding"    contract="DecryptCookie.IService1">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract = "IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>  
</configuration>
Run Code Online (Sandbox Code Playgroud)

当我尝试使用该服务时,我收到如下错误:

Error: The server was unable to process the request due to an internal error. 
For more information about …
Run Code Online (Sandbox Code Playgroud)

wcf wcf-client

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