我正在测试一些WCF服务,它们可以来回发送带有guid的对象。在我的web应用程序测试代码中,我正在做以下事情:

var responseObject = proxy.CallService(new RequestObject
{
    Data = "misc. data",
    Guid = new Guid()
});

由于某些原因,调用new Guid()会生成全为0的Guid,如下所示:

00000000 - the 0000-0000-0000-000000000000

是什么导致了这种情况?

我试图使一个WCF服务在basicHttpBinding上使用https。这是我的web.config:

<!-- language: xml -->
<service behaviorConfiguration="MyServices.PingResultServiceBehavior"
         name="MyServices.PingResultService">
    <endpoint address="" 
              binding="basicHttpBinding" 
              bindingConfiguration="defaultBasicHttpBinding"
              contract="MyServices.IPingResultService">
        <identity>
            <dns value="localhost" />
        </identity>
    </endpoint>
    <endpoint address="mex" 
              binding="mexHttpBinding" 
              contract="IMetadataExchange" />
</service>
...
<bindings>
  <basicHttpBinding>
    <binding name="defaultBasicHttpBinding">
      <security mode="Transport">
        <transport clientCredentialType="None"/>
      </security>
    </binding>
  </basicHttpBinding>
</bindings>
...
<behaviors>
  <serviceBehaviors>
    <behavior name="MyServices.UpdateServiceBehavior">
      <serviceMetadata httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

我使用WCFStorm连接,它能够正确检索所有元数据,但当我调用实际的方法时,我得到:

提供的URI方案'https'无效;预计“http”。参数 名称:通过

好的,我有:

Visual Studio 2010 RC, W7 x64,启动了一个新的项目类型的Silverlight应用程序。在ASP中托管Silverlight应用程序。NET Web应用程序项目。Silverlight 3.0版。 添加了一个LinqToSQL类,一个WCF服务,一个Winform测试应用程序(解决方案中的项目)和一些类(也作为解决方案中的项目)。

昨天,我突然得到了“断点当前不会被击中”。本文档未加载任何符号。'消息出现在IDE中,但它只影响Web Appliaction,我可以调试Silverlight和Winform应用程序。

我尝试/做了什么来摆脱这条信息:

Reset Visual Studio Settings removed all files in every \Temporary ASP.NET Files Folder (there is one for each 32bit/64bit and for Framework 2.0 and 4.0) tried to debug using Visual Studio Integrated Web server - normally I use IIS, in the project output of the solution I deleted every obj and bin folders in every project folder created a new solution and added all the projects to this new solution deleted the solution suo file created a new ASP.NET Web Application to test if it is a VS-installation issue => I can debug this new project/solution rebooted the machine several times repaired the vs.net installation did an IISReset removed the Web App from IIS used the Create Virtual Directory Button under Project Properties of the Web App to create a new Web App in IIS changed the Framework Version of every project from 3.5 to 4.0 Opened the Solution on my second machine => same behavior crawled Microsoft Connect for bugs / similar issues SPENT 7 HOURS.

这是我人生中第二次这样了。上次我通过删除临时ASP解决了这个问题。NET文件文件夹,但这次我需要你的帮助。

我完全搞不清WCF和ASMX web服务。在我的早期阶段,我使用了很多web服务,现在引入了这个叫做WCF的新东西。我仍然可以创建作为web服务功能的WCF。我想WCF里会有更多的东西。

WCF和Web服务之间有什么区别?什么时候应该分别使用?

我已经在VS2008/中添加了web服务的代理。NET 3.5解决方案。在构造客户端。net时会抛出以下错误:

在ServiceModel客户端配置部分中找不到引用合约“IMySOAPWebService”的默认端点元素。这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中没有找到与此契约匹配的端点元素。

搜索此错误告诉我在契约中使用完整的名称空间。这是我的app.config完整的命名空间:

<client>
  <endpoint address="http://192.168.100.87:7001/soap/IMySOAPWebService"
            binding="basicHttpBinding" bindingConfiguration="IMySOAPWebServicebinding"
            contract="Fusion.DataExchange.Workflows.IMySOAPWebService" name="IMySOAPWebServicePort" />
</client>

我正在运行XP本地(我提到这是因为一些谷歌点击提到win2k3) 将app.config复制到app.exe。配置,所以这也不是问题。

有线索吗?

我试图从Web API使用HttpClient POST一个JsonObject。我不太确定如何做到这一点,也找不到很多样例代码。

以下是我目前所了解到的:

var myObject = (dynamic)new JsonObject();
myObject.Data = "some data";
myObject.Data2 = "some more data";

HttpClient httpClient = new HttpClient("myurl");
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

HttpResponseMessage response = httpClient.Post("", ???);

我认为我需要将我的JsonObject转换为StreamContent,但我在这一步上被挂断了。

我喜欢在using块中实例化我的WCF服务客户端,因为它几乎是使用实现IDisposable的资源的标准方式:

using (var client = new SomeWCFServiceClient()) 
{
    //Do something with the client 
}

但是,正如这篇MSDN文章中提到的,将WCF客户端包装在using块中可能会掩盖导致客户端处于故障状态(如超时或通信问题)的任何错误。长话短说,当调用Dispose()时,客户端的Close()方法会触发,但会抛出一个错误,因为它处于故障状态。然后,原始异常被第二个异常掩盖。不好的。

在MSDN文章中建议的解决方法是完全避免使用using块,而是实例化你的客户端,并像这样使用它们:

try
{
    ...
    client.Close();
}
catch (CommunicationException e)
{
    ...
    client.Abort();
}
catch (TimeoutException e)
{
    ...
    client.Abort();
}
catch (Exception e)
{
    ...
    client.Abort();
    throw;
}

与using块相比,我认为它很难看。每次需要客户端时都要写大量代码。

幸运的是,我找到了一些其他的解决方法,比如IServiceOriented博客上的这个(现在已经不存在了)。你可以这样开始:

public delegate void UseServiceDelegate<T>(T proxy); 

public static class Service<T> 
{ 
    public static ChannelFactory<T> _channelFactory = new ChannelFactory<T>(""); 
    
    public static void Use(UseServiceDelegate<T> codeBlock) 
    { 
        IClientChannel proxy = (IClientChannel)_channelFactory.CreateChannel(); 
        bool success = false; 
        try 
        { 
            codeBlock((T)proxy); 
            proxy.Close(); 
            success = true; 
        } 
        finally 
        { 
            if (!success) 
            { 
                proxy.Abort(); 
            } 
        } 
     } 
} 

这就允许:

Service<IOrderService>.Use(orderService => 
{ 
    orderService.PlaceOrder(request); 
}); 

这还不错,但我不认为它像using块那样具有表现力和易于理解。

我目前正在尝试使用的解决方法是我第一次在blog.davidbarret.net上读到的。基本上,无论在哪里使用客户机的Dispose()方法,都要重写它。喜欢的东西:

public partial class SomeWCFServiceClient : IDisposable
{
    void IDisposable.Dispose() 
    {
        if (this.State == CommunicationState.Faulted) 
        {
            this.Abort();
        } 
        else 
        {
            this.Close();
        }
    }
}

这似乎能够允许using块再次出现,而不会有隐藏故障状态异常的危险。

那么,使用这些变通方法还有其他需要注意的问题吗?有没有人想出更好的办法?

我有一个WCF服务,我想把它同时公开为RESTfull服务和SOAP服务。 有人做过类似的事吗?

我有一个WCF服务,从数据库返回1000条记录到客户端。我有一个ASP。NET WCF客户端(我已经在asp.net web应用程序项目中添加了服务引用来使用WCF)。

当我运行客户端应用程序时,我得到以下消息:

传入消息的最大消息大小配额(65536)已为 超过了。如果需要增加配额,使用 MaxReceivedMessageSize属性 适当的绑定元素。

任何帮助吗?如何增加消息大小配额?

我花了几个月的时间试图掌握WCF背后的概念,最近我开发了我的第一个WCF服务应用程序。

为了理解配置文件中的所有设置,我花了不少功夫。 我不相信环境,但似乎你可以用它做惊人的事情。

前几天我发现微软推出了一个叫ASP的新东西。NET Web API。

据我所知,这是一个RESTful框架,非常容易使用和实现。

现在,我试图弄清楚这两个框架之间的主要区别是什么,如果我应该尝试用新的API转换我的旧WCF服务应用程序。

有人能帮我了解一下这两种语言的区别和用法吗?