简体   繁体   中英

Insert operation with WCF rest fails everytime…

Hi I am using WCF Rest in my app with a layered architecture. My dataflow heirarchy is given below:

Data Layer -> Linq2Sql
||
Business Layer
||
WCF Rest Service
||
ASPX Pages

I am using JSON via JQuery to Select/Delete and codebehind to Insert/Update so as I can pass .Net objects to database base through my business layer(to check if i have business logic for them.) using WCF servive.

Forexample , I am ciphering password and deciphering password in my business layer and sending it to datalayer.Anyways, thats not the Issue. The issue is with WCF service configurationsettings. Every time i am getting unique exceptions like:

  1. 404 bad request.
  2. There was no endpoint listening at http://localhost/Service.svc that could accept the message.
  3. Could not find default endpoint element that references contract 'xxx' in the service model client configuaration section. This might be because no configuaration file was found for your application or because no end point element matching this contract could be found in the client element and so on....

What I tried is

  1. As per answer suggested by Tom Haigh . protected Save_Click(sender,e) {

    var user = new User { Login = login.Value, Password = pwd.Value, RealName = realname.Value, AccessRight = accessrights.Value, CustomAccesRight = customaccessrights.Value };

      var remoteAddress = new EndpointAddress("http://localhost:2360/UserService.svc"); using (var client = new UserServiceClient(new BasicHttpBinding(), remoteAddress)) { //set timeout client.Endpoint.Binding.SendTimeout = new TimeSpan(0, 0, 0, 10000); //call ws method client.Insert(user); } //using 

}

  1. I removed using an tried also, got Error 400

    protected Save_Click(sender,e) {

    var user = new User { Login = login.Value, Password = pwd.Value, RealName = realname.Value, AccessRight = accessrights.Value, CustomAccesRight = customaccessrights.Value };

      var remoteAddress = new EndpointAddress("http://localhost:2360/UserService.svc"); var client = new UserServiceClient(new BasicHttpBinding(), remoteAddress); //set timeout client.Endpoint.Binding.SendTimeout = new TimeSpan(0, 0, 0, 10000); //call ws method client.Insert(user); 

}

My Config file of Service:

<system.serviceModel>
    <services>
      <service name="EnergyManagementControl.WcfSvc.UserService"  behaviorConfiguration="ServiceBehaviour" >
        <endpoint name="" binding="webHttpBinding"   contract="EnergyManagementControl.WcfSvc.IUserService" address="http://localhost:2360/UserService.Svc"   behaviorConfiguration="web"></endpoint>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehaviour"  >
          <serviceMetadata  httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>

My Config file of Client

<system.serviceModel>
    <client>
      <endpoint
        name = "Receptor"
         address="http://localhost:2360/UserService.Svc" 
        binding = "wsHttpBinding"
        contract="IUserService"
    />
    </client>
  </system.serviceModel>

But nothing seems to help. I know its config error ,please help me. Also any brief reference on WCF rest based on my scenario will be great help.....

Please not the WCF is created as a WCF Service Application and is a project in my Solution with my Web app. See image below: 在此处输入图片说明

Also I am getting error on WebDev Server,not on IIS or Cassini

I can't speak much to WCF usage for REST services, but your service & client endpoint bindings do not match. WCF uses the binding to find a matching endpoint.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM