【发布时间】:2022-01-23 15:39:15
【问题描述】:
我需要构建一个 wcf 服务,它使用自定义响应,采用 jsonp 格式,我应该得到类似下面示例的响应:
调用这个示例方法:
http://localhost:49350/Service1.svc/TestConnectionWCF_new?callback=jQuery22406768180963924506_1639677943363&_=1639677943368
我必须得到这个答案:
jQuery22406768180963924506_1639677943363( {"d":"<ACCESS><MSG><![CDATA[YES]]><\/MSG><\/ACCESS>"} );
我得到了这个:
{"TestConnectionWCF_NEWResult":"<ACCESS><MSG><![CDATA[YES]]><\/MSG><\/ACCESS>"}
我已经尝试了很多方法,但我还没有超越这个,如果有人可以以任何方式帮助我,即使有一些建议可以超越这个。
我做了一个简单的服务测试wcf,这是我正在使用的代码
界面:
<ServiceContract>
Public Interface IService1
<OperationContract>
<WebGet(ResponseFormat:=WebMessageFormat.Json, BodyStyle:=WebMessageBodyStyle.Wrapped)>
Function TestConnectionWCF_NEW() As Object
End Interface
服务:
Imports Test_Jsonp_Vb
Imports System.ServiceModel.Activation
<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Required)>
Public Class Service1
Implements IService1
Dim oReturnObject As Object
Public Function TestConnectionWCF_NEW() As Object Implements IService1.TestConnectionWCF_NEW
Try
oReturnObject = "<ACCESS><MSG><![CDATA[YES]]></MSG></ACCESS>"
Return oReturnObject
Catch ex As Exception
oReturnObject = ex.Message
Return oReturnObject
End Try
End Function
End Class
服务标记:
<%@ ServiceHost Language="VB" Debug="true" Service="Test_Jsonp_Vb.Service1" CodeBehind="Service1.svc.vb" Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>
网络配置:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
【问题讨论】:
-
您可以阅读这些文章找到解决方案。stackoverflow.com/questions/11090835/… && stackoverflow.com/questions/2067472/…
-
您好,感谢您的链接,我已经看到并尝试过,但仍然无法在那里得到答案。
标签: jquery ajax vb.net wcf jsonp