在WCF中,有几种不同类型的基于HTTP的绑定:
这3个有什么不同?
特别是在功能/性能和兼容性方面有何不同?
我在使用HttpClient和BaseAddress属性调用webHttpBinding WCF端点时遇到问题.
HttpClient的
我创建了一个HttpClient实例,将BaseAddress属性指定为本地主机端点.

GetAsync Call
然后我调用GetAsync方法传递额外的Uri信息.
HttpResponseMessage response = await client.GetAsync(string.Format("/Layouts/{0}", machineInformation.LocalMachineName()));
Run Code Online (Sandbox Code Playgroud)

服务端点
[OperationContract]
[WebGet(UriTemplate = "/Layouts/{machineAssetName}", ResponseFormat = WebMessageFormat.Json)]
List<LayoutsDto> GetLayouts(string machineAssetName);
Run Code Online (Sandbox Code Playgroud)
问题
我遇到的问题是,是,/AndonService.svc所述BaseAddress的一部分被截断,从而将得到的呼叫转到https://localhost:44302/Layouts/1100-00277宁可https://localhost:44302/AndonService.svc/Layouts/1100-00277导致404未找到.
是否有理由在GetAsync调用中截断BaseAddress?我该如何解决这个问题?
我是WCF RESTFull服务开发的新手,我正在寻找一些有用的信息以及有关使用webHttpBinding的经验反馈,与新的WCF Web API http://wcf.codeplex.com/相比.
我正在寻找的是了解webHttpBinding的缺点,以及为什么要使用新的Web api,特别是新API解决的问题.如果你能指点我一些博客文章比较他们或只是谈论使用webHttpBinding时的问题我会很感激.先感谢您.
我已经为我的原型服务成功配置了3个端点.端点是basicHttpBinding,wsHttpBinding和webHttpBinding.我目前唯一的故障是WCFTestClient.当我将它指向我的服务时,它会列出前两个,但不会列出webHttpBinding.我可以通过浏览器测试REST端点,它工作得很好.这是我的配置:
<system.serviceModel>
<services>
<service behaviorConfiguration="serviceBehaviour" name="VMDServices.VMDService">
<endpoint binding="webHttpBinding"
address="rest" behaviorConfiguration="webBehaviour" contract="VMDServices.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint binding="basicHttpBinding"
address="basic" bindingConfiguration="basicBinding" contract="VMDServices.IService1">
</endpoint>
<endpoint binding="wsHttpBinding"
address="ws" bindingConfiguration="wsBinding" contract="VMDServices.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="basicBinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<security mode="None"></security>
<readerQuotas maxStringContentLength="2147483647"/>
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="wsBinding" transactionFlow="true">
<security mode="None"></security>
<reliableSession enabled="true" ordered="true" />
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="webBehaviour">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="serviceBehaviour">
<!-- To avoid disclosing metadata information, set the value below …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用https和http作为网站.该网站有.svc文件,它们充当REST服务并从JavaScript调用.
我的配置:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="AjaxBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="MyServiceBehaviour">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service behaviorConfiguration="MyServiceBehaviour" name="MyService.Lookups">
<endpoint address="" behaviorConfiguration="AjaxBehavior"
binding="webHttpBinding" bindingConfiguration="httpWebBinding" contract="MyService.Lookups" >
</endpoint>
<endpoint address="" behaviorConfiguration="AjaxBehavior"
binding="webHttpBinding" bindingConfiguration="httpsWebBinding" contract="MyService.Lookups" >
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="httpsWebBinding">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" />
</security>
</binding>
<binding name="httpWebBinding">
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" />
</security>
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
我有两个WCF RESTful服务 - "通用"服务是公共的,没有安全性; "admin"服务我打算使用SSL进行基本身份验证.这是我的服务器端web.config:
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="general" maxReceivedMessageSize="2147483647">
<readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" />
<security mode="None">
<transport clientCredentialType="None" />
</security>
</binding>
<binding name="admin" maxReceivedMessageSize="2147483647">
<readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" />
<security mode="Transport">
<transport clientCredentialType="Basic" />
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="MyNamespace.AppServices.GeneralService">
<endpoint address="" binding="webHttpBinding" contract="MyNamespace.Contracts.IGeneralService" behaviorConfiguration="web" bindingConfiguration="general" />
</service>
<service name="MyNamespace.AppServices.AdminService">
<endpoint address="" binding="webHttpBinding" contract="MyNamespace.Contracts.IAdminService" behaviorConfiguration="web" bindingConfiguration="admin" />
</service>
</services>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
在客户端,我目前的代码如下所示:
private static …Run Code Online (Sandbox Code Playgroud) 我在Web上发现了很多关于将ASP.NET成员资格提供程序与wsHttpBindings一起使用的资料,但我没有看到任何与webHttpBindings一起使用它的参考资料.
我正在寻找一个可以在两种情况下工作的系统:
这可能是使用内置框架(即只是通过配置)?如果是这样,我该如何配置服务?用户如何将凭据传递给REST服务?
我正在尝试公开WCT REST服务,只有拥有有效用户名和密码的用户才能访问它.用户名和密码存储在SQL数据库中.
这是服务合同:
public interface IDataService
{
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
byte[] GetData(double startTime, double endTime);
}
Run Code Online (Sandbox Code Playgroud)
这是WCF配置:
<bindings>
<webHttpBinding>
<binding name="SecureBinding">
<security mode="Transport">
<transport clientCredentialType="Basic"/>
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="DataServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceCredentials>
<userNameAuthentication
userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType=
"CustomValidator, WCFHost" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="DataServiceBehavior" name="DataService">
<endpoint address="" binding="webHttpBinding"
bindingConfiguration="SecureBinding" contract="IDataService" />
</service>
</services>
Run Code Online (Sandbox Code Playgroud)
我通过Silverlight应用程序中的WebClient类访问该服务.但是,我无法弄清楚如何将用户凭据传递给服务.我为client.Credentials尝试了各种值,但它们似乎都没有在我的自定义验证器中触发代码.我收到以下错误:基础连接已关闭:发送时发生意外错误.
这是我尝试过的一些示例代码:
WebClient client = new WebClient();
client.Credentials = new NetworkCredential("name", "password", "domain");
client.OpenReadCompleted += new OpenReadCompletedEventHandler(GetData);
client.OpenReadAsync(new Uri(uriString));
Run Code Online (Sandbox Code Playgroud)
如果我将安全模式设置为None,则整个过程都有效.我还尝试了其他clientCredentialType值,但没有一个工作.我还自行托管了WCF服务,以消除与IIS尝试在服务获得机会之前对用户进行身份验证相关的问题.
任何关于潜在问题的评论都会受到高度赞赏.谢谢. …
我现在已经调查了过去两小时的400-BadRequest代码.很多sugestions用于确保正确设置bindingConfiguration属性,在我的例子中,它是.
现在,在摧毁我所在的建筑物之前,我需要你的帮助:-)
我运行WCF RestFull服务(非常轻量级,使用此资源获取灵感:http://msdn.microsoft.com/en-us/magazine/dd315413.aspx),它(现在)接受通过提供的XmlElement(POX) POST动词.
在实现真正的客户端之前,我目前只使用Fiddler的请求构建器(因为这是混合环境).
当我为小于65K的XML执行此操作时,它工作正常 - 更大,它会抛出此异常:已超出传入消息的最大邮件大小配额(65536).要增加配额,请在相应的绑定元素上使用MaxReceivedMessageSize属性.
这是我的web.config文件(我甚至包括了客户端标签(绝望的时候!)):
<system.web>
<httpRuntime maxRequestLength="1500000" executionTimeout="180"/>
</system.web>
<system.serviceModel>
<diagnostics>
<messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" />
</diagnostics>
<bindings>
<webHttpBinding>
<binding name="WebHttpBinding" maxReceivedMessageSize="1500000" maxBufferPoolSize="1500000" maxBufferSize="1500000" closeTimeout="00:03:00" openTimeout="00:03:00" receiveTimeout="00:10:00" sendTimeout="00:03:00">
<readerQuotas maxStringContentLength="1500000" maxArrayLength="1500000" maxBytesPerRead="1500000" />
<security mode="None"/>
</binding>
</webHttpBinding>
</bindings>
<client>
<endpoint address="" binding="webHttpBinding" bindingConfiguration="WebHttpBinding" contract="Commerce.ICatalogue"/>
</client>
<services>
<service behaviorConfiguration="ServiceBehavior" name="Catalogue">
<endpoint address=""
behaviorConfiguration="RestFull"
binding="webHttpBinding"
bindingConfiguration="WebHttpBinding"
contract="Commerce.ICatalogue" />
<!-- endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" / -->
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="RestFull"> …Run Code Online (Sandbox Code Playgroud) 我正在编写一个有很多方法的Web服务.它们都设置类似于以下内容:
[OperationContract]
[WebInvoke(
BodyStyle = WebMessageBodyStyle.Bare,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "x/y/z")]
void someMethod(int x, int y, int z);
Run Code Online (Sandbox Code Playgroud)
我想要做的只是在web.config文件中设置默认的BodyStyle/ RequestFormat/ ResponseFormatall.现在,我知道我可以这样做:
<endpointBehaviors>
<behavior name="webHttpBehavior">
<webHttp defaultBodyStyle="Bare" defaultOutgoingResponseFormat="Json" />
</behavior>
</endpointBehaviors>
Run Code Online (Sandbox Code Playgroud)
但似乎没有RequestFormat的属性.如何将默认设置RequestFormat为JSON?
webhttpbinding ×10
wcf ×8
c# ×3
asp.net ×2
rest ×2
web-config ×2
web-services ×2
.net ×1
credentials ×1
json ×1
request ×1
security ×1
wcf-binding ×1
wcf-rest ×1
wcf-web-api ×1
webclient ×1