简体   繁体   中英

SQL Server database, wcf and WinForm

I have a sweet WinForm application (on my computer) and a SQL Server database (on server X). I'm using SqlConnection and everything works fine.

But not I want to change it and use WCF or other technologies to connect and switch information between my app and database.

I also have one more server to use as application server (Server Y).

I've started using WCF: created project, created installer.

Uploaded it on my Y server and installed it. Service started, also I've added Service Reference to my WinForm app, but the ServiceClient is not working properly.

When I call ServiceClient 's method it throws exception:

An exception of type 'System.ServiceModel.EndpointNotFoundException' occurred in mscorlib.dll but was not handled in user code

Additional information: There was no endpoint listening at http://localhost:41272/service that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

As I guess my endpoint is blowing things up.

So I want you guys help me how to configure SQL endpoint.

Here is my WCF's web.config :

<?xml version="1.0"?>
<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.5" />
        <httpRuntime />
        <pages controlRenderingCompatibilityVersion="4.0" />
    </system.web>
    <system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior name="SampleSvcBehavior">
                    <serviceDebug includeExceptionDetailInFaults="true" />
                    <serviceMetadata httpGetEnabled="true" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <services>
            <service behaviorConfiguration="SampleSvcBehavior"  
                     name="FMG_WCF.FmgService">
                <endpoint name="SampleSvcBasicHttpEndPoint" 
                    address="" 
                    binding="basicHttpBinding" bindingConfiguration=""
                    contract="FMG_WCF.IFmgService" />
                <endpoint name="SampleSvcMexHttpEndPoint" 
                    address="mex" 
                    binding="mexHttpBinding" bindingConfiguration=""
                    contract="IMetadataExchange" />
                <host>
                    <baseAddresses>
                        <add baseAddress="http://localhost:41272/service" />
                    </baseAddresses>
               </host>
            </service>
        </services>
    </system.serviceModel>
</configuration>

This error is not related with SQL endpoint. In facts you do not need endpoints for connecting WCF to database. Here is your answer in another post.

EndpointNotFoundException - 404 - Hosting WCF Service over HTTPS in IIS through Visual Studio

You have two options, if the service has been modified from when you created it you can simply right click on the service reference and configure the service reference. In the popup you can change the Url to point to serverX and you service reference and config file will be automatically updated.

If no changes were made to the service, for example your binding type or security then simply updating the Url in the config file should be enough.

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