通过角度5服务的POST调用WCF Rest服务

时间:2017-12-04 10:54:46

标签: angular rest wcf post

我试图通过角度服务来发布WCF休息服务,但它不起作用,我不知道出了什么问题。我的GET服务正在运行,我可以接收List,然后我做了一些Star mofification,我试图将其发回到WCF服务器。不幸的是我的Save方法没有被调用,我在控制台上看不到任何错误。

我的WCF服务如下所示:

<extensions>
  <behaviorExtensions>
    <add name="crossOriginResourceSharingBehavior" type="SharksHunter.Service.Net.CORSEnablingBehavior, SharksHunter.Service.Net, Version=1.0.0.0, Culture=neutral" />
  </behaviorExtensions>
</extensions>

<services>
  <service behaviorConfiguration="serviceBehavior" name="SharksHunter.Service.Net.StarService">
    <endpoint behaviorConfiguration="webBehavior" address=""
              binding="webHttpBinding" 
              contract="SharksHunter.Service.Net.IStarService" 
  />
  <endpoint   name="mexHttpBinding"
              address="mex"
              binding="mexHttpBinding"
              contract="IMetadataExchange"
              />
  </service>
</services>

<behaviors>
  <endpointBehaviors>
    <behavior name="webBehavior">
      <webHttp />
      <crossOriginResourceSharingBehavior />
    </behavior>
  </endpointBehaviors>

  <serviceBehaviors>
    <behavior name="serviceBehavior">
      <!-- To avoid disclosing metadata information, set the values below to false 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="false" />
    </behavior>
  </serviceBehaviors>

</behaviors>
<protocolMapping>
    <add binding="webHttpBinding" scheme="http" />
</protocolMapping>    

<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

web.xml配置

private starsUrlGet = 'http://localhost:39958/StarService.svc/GetAllStars';  

private starsUrlPost = 'http://localhost:39958/StarService.svc/Save';  


....
this.http.get<Star[]>(this.starsUrlGet); -> this is WORKING


public saveStar(st: Star) 
{

this.http.post<Star>(this.starsUrlPost, st); -> this is not WORKING
}

我的角度服务是这样的:

    <div ng-repeat="region in brain_regions">
        <label>
           <input type="checkbox"
              name="checkbox_brain_region[$index]"
              id="checkbox_brain_region[region.id]"
              value="region.id"              
              ng-model="region.show"
              ng-change="update_selected_Brain_regions(region)">                           
           <b>{{region.name}}</b>
         </label>
    </div>
    <br>
    <label ng-repeat="region in selected_brain_regions">
        <input type="radio" name="radio_brain_regions_graphical_search_soma[$index]"
        ng-model="region.show" value="region.id">
        <b>{{region.name}}</b>
    </label>

在上面的代码中,GET工作正常,但POST根本没有调用,为什么? 非常感谢

0 个答案:

没有答案