Error: Could not find default endpoint element that references contract

試著忘記壹切 提交于 2019-12-06 06:12:41

The problem is in this line:

StreamUploadClient streamClient = new StreamUploadClient()

This is a separate endpoint you are trying to connect to. Typically it would pick adress and all other properties of a connection from app.config, but as you don't have any you need to provide all the required parameters yourself, similar to what you do with your CoreService. Refer to app.config sample to see what paremeters you need.

Something like this:

    public StreamUploadClient GetConnection()
    {
        BasicHttpBinding basicHttpBinding = new BasicHttpBinding
        {
            MaxReceivedMessageSize = 10485760,
            ReaderQuotas = new XmlDictionaryReaderQuotas
            {
                MaxStringContentLength = 10485760,
                MaxArrayLength = 10485760
            },
            MessageEncoding = WSMessageEncoding.Mtom,
            Security = new BasicHttpSecurity
            {
                Mode = BasicHttpSecurityMode.None,
            }
        };

        EndpointAddress remoteAddress = new EndpointAddress("http://abc/webservices/CoreService2011.svc/streamUpload_basicHttp");

        StreamUploadClient client = new StreamUploadClient (basicHttpBinding, remoteAddress);
        try
        {
            client.Open();
        }
        catch (Exception ex)
        {
            log.Error("Error:CoreServiceConectionOpen:Common:" + ex.Message);
            throw ex;
        }

        return client;
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!