- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 WCF 构建通用 Web 服务接口(interface),以允许第 3 方开发人员连接到我们的软件。经过大量的努力和阅读(this question 帮助很大),我终于让 SOAP、JSON 和 XML (POX) 一起工作。
为了简化,这是我的代码(为了使这个例子简单,我没有使用接口(interface)——我确实尝试过这两种方式):
<ServiceContract()> _
Public Class TestService
Public Sub New()
End Sub
<OperationContract()> _
<WebGet()> _
Public Function GetDate() As DateTime
Return Now
End Function
'<WebGet(UriTemplate:="getdateoffset/{numDays}")> _
<OperationContract()> _
Public Function GetDateOffset(ByVal numDays As Integer) As DateTime
Return Now.AddDays(numDays)
End Function
End Class
<services>
<service name="TestService"
behaviorConfiguration="TestServiceBehavior">
<endpoint address="soap" binding="basicHttpBinding" contract="TestService"/>
<endpoint address="json" binding="webHttpBinding" behaviorConfiguration="jsonBehavior" contract="TestService"/>
<endpoint address="xml" binding="webHttpBinding" behaviorConfiguration="poxBehavior" contract="TestService"/>
<endpoint address="mex" contract="IMetadataExchange" binding="mexHttpBinding" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="jsonBehavior">
<enableWebScript/>
</behavior>
<behavior name="poxBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="TestServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
TestService.svc/xml/GetDate
对于 xml,
TestService.svc/json/GetDate
对于 json,并将 SOAP 客户端指向
TestService.svc?wsdl
并让 SOAP 查询工作。
TestService.svc/xml/GetDateOffset?numDays=4
而不是
TestService.svc/xml/GetDateOffset/4
.如果我指定 UriTemplate,我会收到错误消息:
Endpoints using 'UriTemplate' cannot be used with 'System.ServiceModel.Description.WebScriptEnablingBehavior'.
<enableWebScript/>
, JSON 不起作用。
最佳答案
其实<enableWebScript />
“纯” JSON 支持不需要。 WebScriptEnablingBehavior
仅当您想要支持 ASP.NET AJAX 时才需要。通常,如果您尝试使用标准脚本库,您不希望为您的服务启用此支持。
相反,您想要为 JSON 端点做的只是使用 WebHttpBehavior
并设置 DefaultOutgoingResponseFormat="JSON"。问题是,在 .NET 3.5 中,您无法通过配置控制此设置,因为 WebHttpElement
不公开这些属性进行配置。为了在 3.5 中解决这个问题,我提供了一个我称之为 EnhancedWebHttpElement
的实现。 here in this answer到另一个 StackOverflow 问题。
幸运的是,微软意识到了这个缺点并启用了所有 WebHttpBehavior
的配置。通过 WebHttpElement
in 4.0 设置.
关于.net - 使用 UriTemplate 在 WCF 中组合 SOAP/JSON/XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2471358/
[OperationContract] [WebGet(UriTemplate = "/searchresults/{searchTerm}/{searchType}", ResponseFo
当我使用带有 WebGet 属性的参数注释方法但不提供 UriTemplate 时,WCF Rest 的默认行为是什么?是否存在默认行为或 WCF 根本不响应 GET 请求(这对我来说似乎正在发生)。
WCF 将匹配: http://localhost:8888/test/blahFirst/blahSecond/sdfsdf,wwewe 对此: [OperationContract] [WebGe
我尝试重用相同的 UriTemplate 实例,而不是每次都创建它。但不知道是否线程安全。 最佳答案 UriTemplate 接受 URI 字符串,并将其分解为: private final Stri
我尝试了以下代码: [OperationContract] [WebInvoke(UriTemplate="/Users/Register/{user}")] void Register(Use
我正在使用 WCF 4.0 创建 REST-ful Web 服务。我想要做的是根据 UriTemplate 中的查询字符串参数调用不同的服务方法。 例如,我有一个 API,允许用户使用驾驶执照或社会安
我已经使用了 this thread 中的提示并提供了一个默认值,以便当用户没有指定虚拟子目录时,我假设他的意思是要列出所有内容。它有效。 [OperationContract] [WebInvoke
我正在 WCF 4.0 中开发一些 RESTful 服务。我有一个方法如下: [OperationContract] [WebGet(UriTemplate = "Test?format=XM
这是一种场景,我有一个 WCF 服务调用,它采用一个字符串参数,并且该字符串中包含斜杠(例如“123/456.xml”)。我想设置一个像“/{file}”这样的 UriTemplate,以便我可以访问
我正在使用 .Net Standart for Azure Function,它使用服务总线处理消息。一旦我的函数运行,我遇到了以下异常: Microsoft.ServiceBus: The type
如何编写单元测试来测试我的 WCF 服务中的 UriTemplates(例如 [WebGet(Uritemlpate="{clientId}/returns")]? 例如,在 Global.asax
假设我正在使用新的 WCF Web API 来构建 RESTful 服务,并且在我的服务中,我有一部分 URI 将描述目标资源,但用于(几乎)契约(Contract)的所有方法。例如,如果我有一个处理
我创建了以下 RESTful WCF 服务,它在 VS 中运行时运行良好。 [OperationContract] [WebGet(ResponseFormat = WebMessageFormat.
我有许多 Azure 功能,现在我想将 Azure API 管理放在前面。 我已从帐户中的 2 个或 3 个其他函数应用导入所有函数,没有出现任何问题,但其中一个函数应用出现问题。这个功能应用程序有
如果我可以访问 Uri 和它所基于的 UriTemplate,发现替换模板中参数的值的最巧妙方法是什么? 例如,如果我知道: var uriTemplate = new UriTemp
我有以下映射: @RequestMapping(value = "/{first}/**/{last}", method = RequestMethod.GET) public String test
我有一个带有以下 API 的 RESTful WCF 网络服务: [WebGet(ResponseFormat = WebMessageFormat.Json)] MyResponseContract
这些我都试过了 Optional Parameters in WCF Service URI Template?Posted by Kamal Rawat in Blogs | .NET 4.5 on
我可以执行以下操作吗? [OperationContract] [WebGet(UriTemplate = "/foo/{id}")] string GetFoo(int id); 我希望我的服务既可
您好,我有一个简单的 WCF REST 服务,我需要通过如下所示的查询字符串获取一些参数。 page=1&rp=10&sortname=id&sortorder=asc&query=&qtype=Ap
我是一名优秀的程序员,十分优秀!