Tridion 错误:找不到引用协定的默认终结点元素

Tridion 错误:找不到引用协定的默认终结点元素,tridion,tridion-2011,tridion-core-services,Tridion,Tridion 2011,Tridion Core Services,我正在编写下面的代码,通过核心服务在tridion中创建MM组件,但运行此服务时出错 public ComponentData GetNewMultimediaComponent(CoreServiceClient Client, string folderUri, string schemaUri, string title, FileInfo fi) { if (fi.Extension == ".png") { string

我正在编写下面的代码,通过核心服务在tridion中创建MM组件,但运行此服务时出错

 public ComponentData GetNewMultimediaComponent(CoreServiceClient Client, string folderUri, string schemaUri, string title, FileInfo fi)
    {
        if (fi.Extension == ".png")
        {
            string mmType = GetMultiMediaType(fi.Extension);
            if (mmType != null)
            {
                string tempLocation = "";

                UploadResponse us = new UploadResponse();
                using (StreamUploadClient streamClient = GetConnection())
                {
                    FileStream objfilestream = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read);
                    tempLocation = streamClient.UploadBinaryContent(fi.Name.ToLower(), objfilestream);
                }

                BinaryContentData bcd = new BinaryContentData
                {
                    UploadFromFile = fi.FullName,
                    MultimediaType = new LinkToMultimediaTypeData { IdRef = mmType },
                    Filename = fi.Name,
                    IsExternal = false
                };

                ComponentData res = GetNewComponent(folderUri, schemaUri, title);
                res.ComponentType = ComponentType.Multimedia;
                res.BinaryContent = bcd;

                res = (ComponentData)Client.Create(res, new ReadOptions());
在上面的代码中,我在下面的一行中得到了错误

using (StreamUploadClient streamClient = new StreamUploadClient()) 



{System.InvalidOperationException: Could not find default endpoint element that references contract 'Tridion.ContentManager.CoreService.Client.IStreamUpload' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
       at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)
       at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName, Configuration configuration)
       at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName)
       at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address)
       at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress)
       at System.ServiceModel.EndpointTrait`1.CreateSimplexFactory()
       at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait).......
tempLocation = streamClient.UploadBinaryContent(fi.Name.ToLower(), objfilestream);

{System.ServiceModel.ProtocolException: The content type multipart/related; type="application/xop+xml";start="<http://tempuri.org/0>";boundary="uuid:739a821f-aee2-4eaf-9206-05a1ed19311c+id=1";start-info="text/xml" of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 560 bytes of the response were: '
--uuid:739a821f-aee2-4eaf-9206-05a1ed19311c+id=1
Content-ID: <http://tempuri.org/0>
Content-Transfer-Encoding: 8bit
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Header><h:FilePath xmlns:h="http://www.sdltridion.com/ContentManager/CoreService/2011">C:\Windows\TEMP\tmp6841.png</h:FilePath></s:Header><s:Body><UploadResponse xmlns="http://www.sdltridion.com/ContentManager/CoreService/2011"/></s:Body></s:Envelope>
--uuid:739a821f-aee2-4eaf-9206-05a1ed19311c+id=1--
'.
只是为了更新,我正在使用tridioncoreservicesbydll,没有配置文件,并且成功地创建了连接

连接设置

public StreamUploadClient GetConnection()
    {
        BasicHttpBinding basicHttpBinding = new BasicHttpBinding
        {
            MaxReceivedMessageSize = 10485760,
            ReaderQuotas = new XmlDictionaryReaderQuotas
            {
                MaxStringContentLength = 10485760,
                MaxArrayLength = 10485760
            },
            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;
    }
现在,在下面的行中获取错误

using (StreamUploadClient streamClient = new StreamUploadClient()) 



{System.InvalidOperationException: Could not find default endpoint element that references contract 'Tridion.ContentManager.CoreService.Client.IStreamUpload' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
       at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)
       at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName, Configuration configuration)
       at System.ServiceModel.ChannelFactory.ApplyConfiguration(String configurationName)
       at System.ServiceModel.ChannelFactory.InitializeEndpoint(String configurationName, EndpointAddress address)
       at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress)
       at System.ServiceModel.EndpointTrait`1.CreateSimplexFactory()
       at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait).......
tempLocation = streamClient.UploadBinaryContent(fi.Name.ToLower(), objfilestream);

{System.ServiceModel.ProtocolException: The content type multipart/related; type="application/xop+xml";start="<http://tempuri.org/0>";boundary="uuid:739a821f-aee2-4eaf-9206-05a1ed19311c+id=1";start-info="text/xml" of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 560 bytes of the response were: '
--uuid:739a821f-aee2-4eaf-9206-05a1ed19311c+id=1
Content-ID: <http://tempuri.org/0>
Content-Transfer-Encoding: 8bit
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Header><h:FilePath xmlns:h="http://www.sdltridion.com/ContentManager/CoreService/2011">C:\Windows\TEMP\tmp6841.png</h:FilePath></s:Header><s:Body><UploadResponse xmlns="http://www.sdltridion.com/ContentManager/CoreService/2011"/></s:Body></s:Envelope>
--uuid:739a821f-aee2-4eaf-9206-05a1ed19311c+id=1--
'.
templation=streamClient.UploadBinaryContent(fi.Name.ToLower(),objfilestream);
{System.ServiceModel.ProtocolException:响应消息的内容类型multipart/related;type=“application/xop+xml”start=“”;boundary=“uuid:739a821f-aee2-4eaf-9206-05a1ed19311c+id=1”;start info=“text/xml”与绑定的内容类型不匹配(text/xml;charset=utf-8)。如果使用自定义编码器,请确保正确实现IsContentTypeSupported方法。响应的前560字节为:'
--uuid:739a821f-aee2-4eaf-9206-05a1ed19311c+id=1
内容ID:
内容传输编码:8比特
内容类型:application/xop+xml;charset=utf-8;Type=“text/xml”
C:\Windows\TEMP\tmp6841.png
--uuid:739a821f-aee2-4eaf-9206-05a1ed19311c+id=1--
'.

有人能帮我解决这个问题吗?

问题在这一行:

StreamUploadClient streamClient = new StreamUploadClient()
这是您尝试连接到的单独终结点。通常,它会从app.config中选择地址和连接的所有其他属性,但由于您没有任何属性,您需要自己提供所有必需的参数,类似于您使用CoreService所做的操作。请参阅app.config示例以查看您需要的参数

大概是这样的:

    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;
    }

问题出在这一行:

StreamUploadClient streamClient = new StreamUploadClient()
这是您尝试连接到的单独终结点。通常,它会从app.config中选择地址和连接的所有其他属性,但由于您没有任何属性,您需要自己提供所有必需的参数,类似于您使用CoreService所做的操作。请参阅app.config示例以查看您需要的参数

大概是这样的:

    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;
    }

我没有使用app.config文件,在这种情况下,我需要做什么?正如您所发现的,我正在传递我的客户端对象,它包含所有连接详细信息。我理解您的观点,但当我这样做时,在上线templation=streamClient.UploadBinaryContent(fi.Name.ToLower(),objfilestream)上会出现下面的错误;Error:我理解您的观点,但当我这样做时,{System.ServiceModel.ProtocolException:内容类型multipart/related;type=“application/xop+xml”;start上的getdown错误="修复了它,
MessageEncoding=WSMessageEncoding.Mtom
丢失,请参阅更新的示例我没有使用app.config文件,现在在这种情况下我需要做什么?正如您可以找到的,我正在传递我的客户端对象,该对象包含所有连接详细信息。我理解您的观点,但当我这样做时,在上线模板上出现了下面的错误ocation=streamClient.UploadBinaryContent(fi.Name.ToLower(),objfilestream);错误:我理解您的观点,但当我这样做时,上面一行{System.ServiceModel.ProtocolException:content类型multipart/related;type=“application/xop+xml”;start=“修复了它,
MessageEncoding=WSMessageEncoding.Mtom
丢失,请参阅更新的示例。”