Как отправить JSON на веб-службу C # [дублировать]

Потому что вы передаете копию указателя. Чтобы изменить указатель, вам нужно что-то вроде этого:

void foo(int **ptr) //pointer to pointer
{
    *ptr = new int[10]; //just for example, use RAII in a real world
}

или

void bar(int *& ptr) //reference to pointer (a bit confusing look)
{
    ptr = new int[10];
}
4
задан Agustin Meriles 25 March 2013 в 19:36
поделиться

3 ответа

Нехорошо, что у вас есть контракт на обслуживание IContact и контакт с данными Contact. Переименовать контракт службы, например IContactService.

<services>
  <service name="ContactLibrary.ContactService">
    <endpoint address="" binding="webHttpBinding" contract="ContactLibrary.IContactService"  behaviorConfiguration="JsonBehavior" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8732"/>
      </baseAddresses>
    </host>
  </service>
</services>

<behaviors>
  <endpointBehaviors>
    <behavior name="JsonBehavior">
      <webHttp />
    </behavior>
  </endpointBehaviors>
</behaviors>

В течение времени отладки (похоже, у вас есть библиотека WCF), адрес службы будет HTTP: // локальный: 8732 / контакт

4
ответ дан paramosh 18 August 2018 в 13:10
поделиться
  • 1
    Я изменил имена и обновил свой пост. – sebastian.roibu 23 March 2012 в 18:00
  • 2
    «JSONEndpointBehavior» должно быть не Service, а поведение конечной точки – paramosh 23 March 2012 в 18:38

Вам нужно добавить <webHttp/> в список действий endpoint . Кроме того, конечной точке необходимо использовать webHttpBinding. И, наконец, чтобы ответить на GET HTTP-запросы, вам нужно использовать атрибут WebGet (вместо WebInvoke(Method="GET").

  <system.serviceModel> 
    <services> 
      <service name="ContactLibrary.ContactLibrary"> 
        <endpoint address=""
                  binding="webHttpBinding"
                  behaviorConfiguration="JSONEndpointBehavior" 
                  contract="ContactLibrary.IContact"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
        <endpoint address="ws"
                  binding="wsHttpBinding"
                  bindingConfiguration="" 
                  contract="ContactLibrary.IContact" /> 
        <host> 
          <baseAddresses> 
            <add baseAddress="http://localhost/ContactLibrary" /> 
          </baseAddresses> 
        </host> 
      </service> 
    </services> 
    <behaviors> 
      <endpointBehaviors> 
        <behavior name="JSONEndpointBehavior"> 
          <webHttp/> 
        </behavior> 
      </endpointBehaviors> 
      <serviceBehaviors> 
        <behavior> 
          <!-- To avoid disclosing metadata information,  
          set the value below to false and remove the metadata endpoint above before deployment --> 
          <serviceMetadata httpGetEnabled="true"/> 
          <!-- 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="true"/> 
        </behavior> 
      </serviceBehaviors> 
    </behaviors> 
  </system.serviceModel> 

И контракт на обслуживание:

[ServiceContract]  
public interface IContact  
{  
    [OperationContract]  
    [WebGet(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, UriTemplate = "contact")]  
    Contact GetContact(int idContact);        
}  
5
ответ дан carlosfigueira 18 August 2018 в 13:10
поделиться
  • 1
    Я обновил свой пост. – sebastian.roibu 23 March 2012 в 17:58
  • 2
    У вас все еще нет поведения конечной точки. – carlosfigueira 24 March 2012 в 16:49
  • 3
    я отредактирую службу в понедельник, потому что это работа. я буду публиковать снова, если я преуспел, или новая ошибка, которую я получу. – sebastian.roibu 24 March 2012 в 23:21

Я думаю, вы пропустили привязки здесь, вам нужно добавить webHttpBinding и basichttpbing под вкладкой bindings в теге system.serviceModel.

    <services>
  <service name="VInfotech.Server.Intranet.IntranetService" behaviorConfiguration="IntranetService.Service1Behavior">
    <!-- Service Endpoints -->
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="Binding1" contract="VInfotech.Server.Intranet.IIntranet">
      <!-- 
          Upon deployment, the following identity element should be removed or replaced to reflect the 
          identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
          automatically.
      -->
      <identity>
        <dns value="localhost"/>
      </identity>
    </endpoint>
  </service>
  <service name="VInfotech.Server.Intranet.MobileServicesController" behaviorConfiguration="ServBehave">
    <endpoint address="RestService" bindingConfiguration="StreamedRequestWebBinding" binding="webHttpBinding" behaviorConfiguration="restPoxBehavior" contract="VInfotech.Server.Intranet.IMobileServices" />
  </service>
</services>
<bindings>
  <webHttpBinding>
    <binding name="StreamedRequestWebBinding"
    bypassProxyOnLocal="true"
             useDefaultWebProxy="false"
             hostNameComparisonMode="WeakWildcard"
             sendTimeout="10:15:00"
             openTimeout="10:15:00"
             receiveTimeout="10:15:00"
             maxReceivedMessageSize="9223372036854775807"
             maxBufferPoolSize="9223372036854775807"
             maxBufferSize="2147483647"
             transferMode="StreamedRequest" >
      <readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" />
    </binding>
  </webHttpBinding>
  <basicHttpBinding>
    <binding name="Binding1" closeTimeout="04:01:00" openTimeout="04:01:00" receiveTimeout="04:10:00" sendTimeout="04:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="1073741824" maxBufferPoolSize="1073741824" maxReceivedMessageSize="1073741824" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
      <readerQuotas maxDepth="1073741824" maxStringContentLength="1073741824" maxArrayLength="1073741824" maxBytesPerRead="1073741824" maxNameTableCharCount="1073741824"/>
    </binding>
    <!-- For Cyber Source bindings-->
    <binding name="ITransactionProcessor" closeTimeout="04:01:00" openTimeout="04:01:00" receiveTimeout="04:10:00" sendTimeout="04:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="1073741824" maxBufferPoolSize="1073741824" maxReceivedMessageSize="1073741824" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
      <readerQuotas maxDepth="1073741824" maxStringContentLength="1073741824" maxArrayLength="1073741824" maxBytesPerRead="1073741824" maxNameTableCharCount="1073741824"/>
      <security mode="TransportWithMessageCredential">
        <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
        <message clientCredentialType="UserName" algorithmSuite="Default"/>
      </security>
    </binding>
  </basicHttpBinding>
  <!--Cyber Source bindings ends here-->
</bindings>
2
ответ дан Nilesh Rathod 18 August 2018 в 13:10
поделиться
  • 1
    пожалуйста, измените параметры в соответствии с вашими требованиями и оставайтесь так же, как и другие теги, которые вы уже добавили. – Nilesh Rathod 3 April 2013 в 14:59
Другие вопросы по тегам:

Похожие вопросы: