列表的WCF休息服务 - json无法正常工作

时间:2014-08-16 18:43:07

标签: json wcf rest

我的wcf重置服务只有2个合同,一个总是工作,另一个不起作用。

服务代码:

Public Class BasicServ
     Implements IBasicServ

        Public Function DoWork() Implements IBasicServ.DoWork
            Return "Working"
        End Function

        Function Authorize(ByVal id As String, ByVal pw As String) Implements IBasicServ.Authorize
            Dim c As New List(Of Guid)
            For i = 0 To 10
                c.Add(Guid.NewGuid)
            Next
            Return c
            'Return Guid.NewGuid
        End Function
    End Class

合同文件代码:

<ServiceContract()>
Public Interface IBasicServ

    <OperationContract()>
    <WebGet(UriTemplate:="test/", BodyStyle:=WebMessageBodyStyle.Wrapped, RequestFormat:=WebMessageFormat.Json, ResponseFormat:=WebMessageFormat.Json)>
    Function DoWork()

    <OperationContract()>
    <WebGet(UriTemplate:="Authorize/{id}/{pw}", BodyStyle:=WebMessageBodyStyle.Wrapped, RequestFormat:=WebMessageFormat.Json, ResponseFormat:=WebMessageFormat.Json)>
    Function Authorize(ByVal id As String, ByVal pw As String)


End Interface

Web配置文件:

<?xml version="1.0"?>
<configuration>
  <system.diagnostics> 
   <sources>
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
          <add name="messagelistener"
               type="System.Diagnostics.XmlWriterTraceListener" 
                      initializeData="d:\logs\myMessages.svclog"></add>
        </listeners>
      </source>
    </sources>
  <trace autoflush="true"/>
  </system.diagnostics> 

    <system.web>
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
  </system.web>

  <system.serviceModel>
     <diagnostics>
       <messageLogging logEntireMessage="true"
                        logMessagesAtServiceLevel="false"
                        logMessagesAtTransportLevel="false"
                        logMalformedMessages="true"
                        maxMessagesToLog="5000"
                        maxSizeOfMessageToLog="2000">         
       </messageLogging>
     </diagnostics>

    <services>
      <service behaviorConfiguration="ServBehav" name="AssistantWcf.BasicServ">
        <endpoint address="auth" behaviorConfiguration="EndBehav" binding="webHttpBinding" name="endpointname" contract="AssistantWcf.IBasicServ" />
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="EndBehav">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="ServBehav">
          <!-- To avoid disclosing metadata information, set the value below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpGetBinding="webHttpBinding" httpGetBindingConfiguration="" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
  </system.webServer>

</configuration>

在调试/测试时,我发现,如果我在Authoriza方法中只返回1个GUID,它就可以了,但是当我发送GUID列表时,它无法正常工作,并且没有创建SVClog文件。能否帮助我更好地了解WCF REST服务?谢谢。

1 个答案:

答案 0 :(得分:0)

从上面的评论和几个实验中,问题的解决方案是,如果返回类型是字符串,则不是必需的,但如果是其他任何内容,则必须指定返回类型。如果始终提供返回类型,则更好。